hush: fix raw ^C handlisg in single-quoted strings
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 13 Jan 2018 18:14:27 +0000 (19:14 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 13 Jan 2018 18:14:27 +0000 (19:14 +0100)
function                                             old     new   delta
parse_stream                                        2719    2754     +35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash_test/ash-misc/control_char1.right
shell/ash_test/ash-misc/control_char1.tests
shell/ash_test/ash-misc/for_with_bslashes.right
shell/ash_test/ash-misc/for_with_bslashes.tests
shell/hush.c
shell/hush_test/hush-misc/control_char1.right
shell/hush_test/hush-misc/control_char1.tests
shell/hush_test/hush-misc/for_with_bslashes.right
shell/hush_test/hush-misc/for_with_bslashes.tests

index 9498b420d365ce095d7a45d8897666ba9537a4ae..6f8c2533cb208798cb87bbb53c19d9b86f749046 100644 (file)
@@ -1,2 +1,3 @@
 \ 3
+b\ 3#\ 3c
 Done:0
index a2ebeba1bd467d4da139b5d847e7bd6d2ba4e77e..0cfe601417437b3f95db7c766b6c25d66d16a722 100755 (executable)
@@ -1,2 +1,3 @@
 echo \ 3
+echo 'b\ 3#\ 3c'
 echo Done:$?
index 02d96692c6827c69e1d44b2271b70adffff1f77b..cd85010505de15bec5056a9f2f26ab73e12aa0ac 100644 (file)
@@ -5,4 +5,5 @@ b"c
 b'c
 b$c
 b`true`c
+b\ 3#\ 3c
 Zero:0
index 363f3d85b3b8e45998fd8524ff565c5b33c4ea1c..8acd9808ad89afd9e01c55f3c25cf466232b9653 100755 (executable)
@@ -1,9 +1,5 @@
-# UNFIXED BUG.
-# commented-out words contain ^C character.
-# It's a SPECIAL_VAR_SYMBOL, for now hush does not escape it.
-# When it is fixed, update this test.
-
-for a in 'a' 'b\c' 'b\\c' 'b"c' "b'c" 'b$c' 'b`true`c' ### 'b\ 3#\ 3c'
+# last word contains ^C character.
+for a in 'a' 'b\c' 'b\\c' 'b"c' "b'c" 'b$c' 'b`true`c' 'b\ 3#\ 3c'
 do
     echo $a
 done
index fc8940d3d1083d78fd4d6c4b04446ad3b4be65aa..79d7a53ddb26391ea27b1d7eac699d6e6c571407 100644 (file)
@@ -5225,6 +5225,11 @@ static struct pipe *parse_stream(char **pstring,
                                        nommu_addchr(&ctx.as_string, ch);
                                        if (ch == '\'')
                                                break;
+                                       if (ch == SPECIAL_VAR_SYMBOL) {
+                                               /* Convert raw ^C to corresponding special variable reference */
+                                               o_addchr(&dest, SPECIAL_VAR_SYMBOL);
+                                               o_addchr(&dest, SPECIAL_VAR_QUOTED_SVS);
+                                       }
                                        o_addqchr(&dest, ch);
                                }
                        }
index 9498b420d365ce095d7a45d8897666ba9537a4ae..6f8c2533cb208798cb87bbb53c19d9b86f749046 100644 (file)
@@ -1,2 +1,3 @@
 \ 3
+b\ 3#\ 3c
 Done:0
index a2ebeba1bd467d4da139b5d847e7bd6d2ba4e77e..0cfe601417437b3f95db7c766b6c25d66d16a722 100755 (executable)
@@ -1,2 +1,3 @@
 echo \ 3
+echo 'b\ 3#\ 3c'
 echo Done:$?
index 02d96692c6827c69e1d44b2271b70adffff1f77b..cd85010505de15bec5056a9f2f26ab73e12aa0ac 100644 (file)
@@ -5,4 +5,5 @@ b"c
 b'c
 b$c
 b`true`c
+b\ 3#\ 3c
 Zero:0
index 363f3d85b3b8e45998fd8524ff565c5b33c4ea1c..8acd9808ad89afd9e01c55f3c25cf466232b9653 100755 (executable)
@@ -1,9 +1,5 @@
-# UNFIXED BUG.
-# commented-out words contain ^C character.
-# It's a SPECIAL_VAR_SYMBOL, for now hush does not escape it.
-# When it is fixed, update this test.
-
-for a in 'a' 'b\c' 'b\\c' 'b"c' "b'c" 'b$c' 'b`true`c' ### 'b\ 3#\ 3c'
+# last word contains ^C character.
+for a in 'a' 'b\c' 'b\\c' 'b"c' "b'c" 'b$c' 'b`true`c' 'b\ 3#\ 3c'
 do
     echo $a
 done