[git commit] hush: fix raw ^C handlisg in single-quoted strings

Denys Vlasenko vda.linux at googlemail.com
Sat Jan 13 18:14:27 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=9809a82b5983ac3184906fff2df48765dab372c8
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
parse_stream                                        2719    2754     +35

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash_test/ash-misc/control_char1.right       | 1 +
 shell/ash_test/ash-misc/control_char1.tests       | 1 +
 shell/ash_test/ash-misc/for_with_bslashes.right   | 1 +
 shell/ash_test/ash-misc/for_with_bslashes.tests   | 8 ++------
 shell/hush.c                                      | 5 +++++
 shell/hush_test/hush-misc/control_char1.right     | 1 +
 shell/hush_test/hush-misc/control_char1.tests     | 1 +
 shell/hush_test/hush-misc/for_with_bslashes.right | 1 +
 shell/hush_test/hush-misc/for_with_bslashes.tests | 8 ++------
 9 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/shell/ash_test/ash-misc/control_char1.right b/shell/ash_test/ash-misc/control_char1.right
index 9498b42..6f8c253 100644
--- a/shell/ash_test/ash-misc/control_char1.right
+++ b/shell/ash_test/ash-misc/control_char1.right
@@ -1,2 +1,3 @@
 
+b#c
 Done:0
diff --git a/shell/ash_test/ash-misc/control_char1.tests b/shell/ash_test/ash-misc/control_char1.tests
index a2ebeba..0cfe601 100755
--- a/shell/ash_test/ash-misc/control_char1.tests
+++ b/shell/ash_test/ash-misc/control_char1.tests
@@ -1,2 +1,3 @@
 echo 
+echo 'b#c'
 echo Done:$?
diff --git a/shell/ash_test/ash-misc/for_with_bslashes.right b/shell/ash_test/ash-misc/for_with_bslashes.right
index 02d9669..cd85010 100644
--- a/shell/ash_test/ash-misc/for_with_bslashes.right
+++ b/shell/ash_test/ash-misc/for_with_bslashes.right
@@ -5,4 +5,5 @@ b"c
 b'c
 b$c
 b`true`c
+b#c
 Zero:0
diff --git a/shell/ash_test/ash-misc/for_with_bslashes.tests b/shell/ash_test/ash-misc/for_with_bslashes.tests
index 363f3d8..8acd980 100755
--- a/shell/ash_test/ash-misc/for_with_bslashes.tests
+++ b/shell/ash_test/ash-misc/for_with_bslashes.tests
@@ -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#c'
+# last word contains ^C character.
+for a in 'a' 'b\c' 'b\\c' 'b"c' "b'c" 'b$c' 'b`true`c' 'b#c'
 do
     echo $a
 done
diff --git a/shell/hush.c b/shell/hush.c
index fc8940d..79d7a53 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -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);
 				}
 			}
diff --git a/shell/hush_test/hush-misc/control_char1.right b/shell/hush_test/hush-misc/control_char1.right
index 9498b42..6f8c253 100644
--- a/shell/hush_test/hush-misc/control_char1.right
+++ b/shell/hush_test/hush-misc/control_char1.right
@@ -1,2 +1,3 @@
 
+b#c
 Done:0
diff --git a/shell/hush_test/hush-misc/control_char1.tests b/shell/hush_test/hush-misc/control_char1.tests
index a2ebeba..0cfe601 100755
--- a/shell/hush_test/hush-misc/control_char1.tests
+++ b/shell/hush_test/hush-misc/control_char1.tests
@@ -1,2 +1,3 @@
 echo 
+echo 'b#c'
 echo Done:$?
diff --git a/shell/hush_test/hush-misc/for_with_bslashes.right b/shell/hush_test/hush-misc/for_with_bslashes.right
index 02d9669..cd85010 100644
--- a/shell/hush_test/hush-misc/for_with_bslashes.right
+++ b/shell/hush_test/hush-misc/for_with_bslashes.right
@@ -5,4 +5,5 @@ b"c
 b'c
 b$c
 b`true`c
+b#c
 Zero:0
diff --git a/shell/hush_test/hush-misc/for_with_bslashes.tests b/shell/hush_test/hush-misc/for_with_bslashes.tests
index 363f3d8..8acd980 100755
--- a/shell/hush_test/hush-misc/for_with_bslashes.tests
+++ b/shell/hush_test/hush-misc/for_with_bslashes.tests
@@ -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#c'
+# last word contains ^C character.
+for a in 'a' 'b\c' 'b\\c' 'b"c' "b'c" 'b$c' 'b`true`c' 'b#c'
 do
     echo $a
 done


More information about the busybox-cvs mailing list