summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-02-21 03:19:13 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-02-21 03:19:13 (EST)
commit84bc61b8d596f3d342980e98b9c580d655ea0778 (patch)
treec6151065926df4dcbe8859751526150f85687da3
parente86c3c67d60c8b240b1693cda7af5079e39e8dce (diff)
downloadeggshell-84bc61b8d596f3d342980e98b9c580d655ea0778.zip
eggshell-84bc61b8d596f3d342980e98b9c580d655ea0778.tar.gz
eggshell-84bc61b8d596f3d342980e98b9c580d655ea0778.tar.bz2
Improve backslash and quote handling in words
-rw-r--r--parsing/lexer.sh21
-rw-r--r--parsing/parse.sh14
2 files changed, 30 insertions, 5 deletions
diff --git a/parsing/lexer.sh b/parsing/lexer.sh
index c856d99..53af926 100644
--- a/parsing/lexer.sh
+++ b/parsing/lexer.sh
@@ -429,6 +429,23 @@ scan_word()
'command substitution not supported'
break
;;
+ \\)
+ word="${word}${c}"
+ lgetc
+ case "${c}" in '')
+ # Bash, ksh93, mksh, and zsh ignore a
+ # backslash at the end of a file, but
+ # dash and BusyBox ash include it in the
+ # word. To help with script
+ # portability, we'll throw an error
+ # (which is a reasonable thing to do
+ # anyway).
+ synerr 'Unexpected end of file %s' \
+ 'after "\"'
+ ;;
+ esac
+ word="${word}${c}"
+ ;;
\')
word="${word}${c}"
while :; do
@@ -461,6 +478,10 @@ scan_word()
lgetc
done
+ if ${quoted}; then
+ synerr 'Unterminated quoted string'
+ fi
+
printf "%d${RS}%c${RS}%s" ${lines} "${c}" "${word}"
}
diff --git a/parsing/parse.sh b/parsing/parse.sh
index 600a247..c9e8000 100644
--- a/parsing/parse.sh
+++ b/parsing/parse.sh
@@ -659,9 +659,13 @@ try()
#try 'foo <<EOF' 'bar' 'EOF'
#try 'foo <<-EOF' "${HT}bar" "${HT}EOF"
#try 'foo <<EOF' '$(bar)' 'EOF'
-try 'foo <<E"O"F' '$(bar)' 'EOF'
-try 'foo <<"EOF"' '$(bar)' 'EOF'
-try 'foo <<E\OF' '$(bar)' 'EOF'
-try 'foo <<\EOF' '$(bar)' 'EOF'
+#try 'foo <<E"O"F' '$(bar)' 'EOF'
+#try 'foo <<"EOF"' '$(bar)' 'EOF'
+#try 'foo <<E\OF' '$(bar)' 'EOF'
+#try 'foo <<\EOF' '$(bar)' 'EOF'
#try 'foo <<EOF1; bar <<EOF2' 'baz' 'EOF1' 'qux' 'EOF2'
-try '\foo'
+#try '\foo'
+try '"foo bar" baz'
+try '"foo'
+try 'foo\" bar'
+try 'foo\'