ash: [PARSER] Recognise here-doc delimiters terminated by EOF
Upstream commit 1: Date: Wed, 26 Sep 2007 17:14:16 +0800 [PARSER] Recognise here-doc delimiters terminated by EOF Previously dash required a <newline> character to be present in order for a here-document delimiter to be detected. Allowing EOF in the absence of a <newline> to play the same purpose allows some intuitive scripts to succeed. POSIX seems to be silence on this so this should be OK. Test case: eval 'cat <<- NOT test NOT' echo OK Old result: test NOTOK New result: test OK Upstream commit 2: Date: Sat, 20 Oct 2007 18:49:31 +0800 [PARSER] Fix here-doc corruption The change [PARSER] Recognise here-doc delimiters terminated by EOF introduced a regerssion whereby lines starting with eofmark but are not equal to eofmark would be corrupted. This patch fixes it. Test case: cat << _ACEOF _ASBOX _ACEOF Old result: SASBOX New result: _ASBOX Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
f15aa57a7f
commit
350e686f3b
12
shell/ash.c
12
shell/ash.c
@ -11592,11 +11592,17 @@ checkend: {
|
|||||||
if (c == *eofmark) {
|
if (c == *eofmark) {
|
||||||
if (pfgets(line, sizeof(line)) != NULL) {
|
if (pfgets(line, sizeof(line)) != NULL) {
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
|
int cc;
|
||||||
|
|
||||||
p = line;
|
p = line;
|
||||||
for (q = eofmark + 1; *q && *p == *q; p++, q++)
|
for (q = eofmark + 1;; p++, q++) {
|
||||||
continue;
|
cc = *p;
|
||||||
if (*p == '\n' && *q == '\0') {
|
if (cc == '\n')
|
||||||
|
cc = 0;
|
||||||
|
if (!*q || cc != *q)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (cc == *q) {
|
||||||
c = PEOF;
|
c = PEOF;
|
||||||
nlnoprompt();
|
nlnoprompt();
|
||||||
} else {
|
} else {
|
||||||
|
2
shell/ash_test/ash-heredoc/heredoc6.right
Normal file
2
shell/ash_test/ash-heredoc/heredoc6.right
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
test
|
||||||
|
OK:0
|
4
shell/ash_test/ash-heredoc/heredoc6.tests
Executable file
4
shell/ash_test/ash-heredoc/heredoc6.tests
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
eval 'cat <<- NOT
|
||||||
|
test
|
||||||
|
NOT'
|
||||||
|
echo OK:$?
|
1
shell/ash_test/ash-heredoc/heredoc7.right
Normal file
1
shell/ash_test/ash-heredoc/heredoc7.right
Normal file
@ -0,0 +1 @@
|
|||||||
|
_ASBOX
|
3
shell/ash_test/ash-heredoc/heredoc7.tests
Executable file
3
shell/ash_test/ash-heredoc/heredoc7.tests
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
cat << _ACEOF
|
||||||
|
_ASBOX
|
||||||
|
_ACEOF
|
2
shell/hush_test/hush-heredoc/heredoc6.right
Normal file
2
shell/hush_test/hush-heredoc/heredoc6.right
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
test
|
||||||
|
OK:0
|
4
shell/hush_test/hush-heredoc/heredoc6.tests
Executable file
4
shell/hush_test/hush-heredoc/heredoc6.tests
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
eval 'cat <<- NOT
|
||||||
|
test
|
||||||
|
NOT'
|
||||||
|
echo OK:$?
|
1
shell/hush_test/hush-heredoc/heredoc7.right
Normal file
1
shell/hush_test/hush-heredoc/heredoc7.right
Normal file
@ -0,0 +1 @@
|
|||||||
|
_ASBOX
|
3
shell/hush_test/hush-heredoc/heredoc7.tests
Executable file
3
shell/hush_test/hush-heredoc/heredoc7.tests
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
cat << _ACEOF
|
||||||
|
_ASBOX
|
||||||
|
_ACEOF
|
Loading…
Reference in New Issue
Block a user