diff --git a/libdash/printer.py b/libdash/printer.py index 4317638..6c84f2a 100644 --- a/libdash/printer.py +++ b/libdash/printer.py @@ -408,14 +408,7 @@ def string_of_arg (args, quote_mode=UNQUOTED): text = [] while i < len(args): c = string_of_arg_char(args[i], quote_mode=quote_mode) - - # dash will parse '$?' as - # [(C, '$'), (E, '?')] - # but we don't normally want to escape ? - # - # so we check up after the fact: if the character after $ is escaped, - # we'll escape the $, too - if c == "$" and (i+1 < len(args)) and args[i+1][0] == "E": + if c == "$" and (i+1 < len(args)): c = "\\$" text.append(c) diff --git a/ocaml/ast.ml b/ocaml/ast.ml index 9205e83..80a77d4 100644 --- a/ocaml/ast.ml +++ b/ocaml/ast.ml @@ -468,7 +468,7 @@ and string_of_arg ?quote_mode:(quote_mode=QUnquoted) = function | [] -> "" | c :: a -> let char = string_of_arg_char ~quote_mode c in - if char = "$" && next_is_escaped a + if char = "$" && a <> [] then "\\$" ^ string_of_arg ~quote_mode a else char ^ string_of_arg ~quote_mode a diff --git a/test/round_trip.sh b/test/round_trip.sh index 1fbc86b..df7c7af 100755 --- a/test/round_trip.sh +++ b/test/round_trip.sh @@ -8,6 +8,10 @@ fi p=$1 tgt=$2 +two_roundtrips() { + [ "$(head -n1 "$tgt")" != '# TEST: single roundtrip' ] +} + orig=$(mktemp) "$p" "$tgt" >"$orig" @@ -31,25 +35,31 @@ then echo "PASS '$tgt'" exit 0 else - # try one more time around the loop - rtrt=$(mktemp) - - "$p" "$rt" >"$rtrt" - if [ "$?" -ne 0 ] + if two_roundtrips then - echo "RT_ABORT_3: '$tgt' -> '$orig' -> '$rt' -> '$rtrt'" - exit 5 - fi + # try one more time around the loop + rtrt=$(mktemp) - if diff -b "$rt" "$rtrt" >/dev/null - then - echo "PASS '$tgt' (two runs to fixpoint)" - exit 0 + "$p" "$rt" >"$rtrt" + if [ "$?" -ne 0 ] + then + echo "RT_ABORT_3: '$tgt' -> '$orig' -> '$rt' -> '$rtrt'" + exit 5 + fi + + if diff -b "$rt" "$rtrt" >/dev/null + then + echo "PASS '$tgt' (two runs to fixpoint)" + exit 0 + fi fi - + echo "FAIL: '$tgt' first time" diff -ub "$orig" "$rt" - echo ">>> '$tgt' second time" - diff -ub "$rt" "$rtrt" + if two_roundtrips + then + echo ">>> '$tgt' second time" + diff -ub "$rt" "$rtrt" + fi exit 1 fi diff --git a/test/tests/single_quoted_dollar_sign.sh b/test/tests/single_quoted_dollar_sign.sh new file mode 100644 index 0000000..53d1edc --- /dev/null +++ b/test/tests/single_quoted_dollar_sign.sh @@ -0,0 +1,4 @@ +# TEST: single roundtrip + +echo '$1' +echo $ a