From 84bc61b8d596f3d342980e98b9c580d655ea0778 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sun, 21 Feb 2016 03:19:13 -0500 Subject: Improve backslash and quote handling in words --- (limited to 'parsing') 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 <