aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-05 22:19:28 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-05 22:19:28 +0200
commit4142f0187dcf8454e8d2a8d16b321dbd573c170e (patch)
tree88fca8c1cc9b6b213160d386c66ede7026bf7c08
parented79a636238ec15c562862787dd71cd9de168b7d (diff)
downloadbusybox-4142f0187dcf8454e8d2a8d16b321dbd573c170e.tar.gz
ash: fix escaping of a few characters (broken by last commits)
Add a testcase which tests all ASCII punctuation escapes. NB: hush is failing this test! Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c9
-rw-r--r--shell/ash_test/ash-quoting/quoted_punct.right35
-rwxr-xr-xshell/ash_test/ash-quoting/quoted_punct.tests41
3 files changed, 83 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 9b1f57949..946e8726e 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -5939,12 +5939,17 @@ rmescapes(char *str, int flag)
* (for example, glibc <= 2.22).
*
* Lets add "\" only on the chars which need it.
+ * Testcases for less obvious chars are shown.
*/
if (*p == '*'
|| *p == '?'
|| *p == '['
- /* || *p == ']' maybe also this? */
- || *p == '\\'
+ || *p == '\\' /* case '\' in \\ ) echo ok;; *) echo WRONG;; esac */
+ || *p == ']' /* case ']' in [a\]] ) echo ok;; *) echo WRONG;; esac */
+ || *p == '-' /* case '-' in [a\-c]) echo ok;; *) echo WRONG;; esac */
+ || *p == '!' /* case '!' in [\!] ) echo ok;; *) echo WRONG;; esac */
+ /* Some libc support [^negate], that's why "^" also needs love */
+ || *p == '^' /* case '^' in [\^] ) echo ok;; *) echo WRONG;; esac */
) {
*q++ = '\\';
}
diff --git a/shell/ash_test/ash-quoting/quoted_punct.right b/shell/ash_test/ash-quoting/quoted_punct.right
new file mode 100644
index 000000000..ab66c3ce0
--- /dev/null
+++ b/shell/ash_test/ash-quoting/quoted_punct.right
@@ -0,0 +1,35 @@
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
+ok
diff --git a/shell/ash_test/ash-quoting/quoted_punct.tests b/shell/ash_test/ash-quoting/quoted_punct.tests
new file mode 100755
index 000000000..83ee40bf4
--- /dev/null
+++ b/shell/ash_test/ash-quoting/quoted_punct.tests
@@ -0,0 +1,41 @@
+# Testing glob-escaping of every ASCII punctuation char
+# Some chars have more than one test
+# 21..2f
+case '!' in [\!] ) echo ok;; *) echo 'WRONG!';; esac
+case '"' in [\"] ) echo ok;; *) echo 'WRONG"';; esac
+case '#' in [\#] ) echo ok;; *) echo 'WRONG#';; esac
+case '$' in [\$] ) echo ok;; *) echo 'WRONG$';; esac
+case '%' in [\%] ) echo ok;; *) echo 'WRONG%';; esac
+case '&' in [\&] ) echo ok;; *) echo 'WRONG&';; esac
+case "'" in [\'] ) echo ok;; *) echo "WRONG'";; esac
+case '(' in [\(] ) echo ok;; *) echo 'WRONG(';; esac
+case ')' in [\)] ) echo ok;; *) echo 'WRONG)';; esac
+case '*' in [\*] ) echo ok;; *) echo 'WRONG*';; esac
+case '+' in [\+] ) echo ok;; *) echo 'WRONG+';; esac
+case ',' in [\,] ) echo ok;; *) echo 'WRONG,';; esac
+case '-' in [\-] ) echo ok;; *) echo 'WRONG-';; esac
+case '-' in [a\-c]) echo ok;; *) echo 'WRONGa\-c';; esac
+case '.' in [\.] ) echo ok;; *) echo 'WRONG.';; esac
+case '/' in [\/] ) echo ok;; *) echo 'WRONG/';; esac
+# 3a..40
+case ':' in [\:] ) echo ok;; *) echo 'WRONG:';; esac
+case ';' in [\;] ) echo ok;; *) echo 'WRONG;';; esac
+case '<' in [\<] ) echo ok;; *) echo 'WRONG<';; esac
+case '=' in [\=] ) echo ok;; *) echo 'WRONG=';; esac
+case '>' in [\>] ) echo ok;; *) echo 'WRONG>';; esac
+case '?' in [\?] ) echo ok;; *) echo 'WRONG?';; esac
+case '@' in [\@] ) echo ok;; *) echo 'WRONG@';; esac
+# 5b..60
+case '[' in [\[] ) echo ok;; *) echo 'WRONG[';; esac
+case '\' in [\\] ) echo ok;; *) echo 'WRONG\';; esac
+case '\' in \\ ) echo ok;; *) echo 'WRONG\\';; esac
+case ']' in [\]] ) echo ok;; *) echo 'WRONG]';; esac
+case ']' in [a\]]) echo ok;; *) echo 'WRONGa]';; esac
+case '^' in [\^] ) echo ok;; *) echo 'WRONG^';; esac
+case '_' in [\_] ) echo ok;; *) echo 'WRONG_';; esac
+case '`' in [\`] ) echo ok;; *) echo 'WRONG`';; esac
+# 7b..7e
+case '{' in [\{] ) echo ok;; *) echo 'WRONG{';; esac
+case '|' in [\|] ) echo ok;; *) echo 'WRONG|';; esac
+case '}' in [\}] ) echo ok;; *) echo 'WRONG}';; esac
+case '~' in [\~] ) echo ok;; *) echo 'WRONG~';; esac