diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-08-11 18:44:11 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-08-11 18:44:11 +0200 |
commit | 4bf08542480fe6271692cc9359f9747e9d727a79 (patch) | |
tree | f8657908d94e2eabbd03abe79a163475d061c8c9 | |
parent | eb54ca8be0b45a101f9bdcf6efa26645c6b94a08 (diff) | |
download | busybox-w32-4bf08542480fe6271692cc9359f9747e9d727a79.tar.gz busybox-w32-4bf08542480fe6271692cc9359f9747e9d727a79.tar.bz2 busybox-w32-4bf08542480fe6271692cc9359f9747e9d727a79.zip |
hush: add a comment on how globbing (should) work
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/shell/hush.c b/shell/hush.c index 3c19bceaa..4b46752a3 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -3151,6 +3151,41 @@ static int o_get_last_ptr(o_string *o, int n) | |||
3151 | return ((int)(uintptr_t)list[n-1]) + string_start; | 3151 | return ((int)(uintptr_t)list[n-1]) + string_start; |
3152 | } | 3152 | } |
3153 | 3153 | ||
3154 | /* | ||
3155 | * Globbing routines. | ||
3156 | * | ||
3157 | * Most words in commands need to be globbed, even ones which are | ||
3158 | * (single or double) quoted. This stems from the possiblity of | ||
3159 | * constructs like "abc"* and 'abc'* - these should be globbed. | ||
3160 | * Having a different code path for fully-quoted strings ("abc", | ||
3161 | * 'abc') would only help performance-wise, but we still need | ||
3162 | * code for partially-quoted strings. | ||
3163 | * | ||
3164 | * Unfortunately, if we want to match bash and ash behavior in all cases, | ||
3165 | * the logic can't be see as "shell-syntax argument is first transformed | ||
3166 | * to a string, then globbed, and if globbing does not match anything, | ||
3167 | * it is used verbatim". Here are two examples where it fails: | ||
3168 | * | ||
3169 | * echo 'b\*'? | ||
3170 | * | ||
3171 | * The globbing can't be avoided (because of '?' at the end). | ||
3172 | * The glob pattern is: b\\\*? - IOW, both \ and * are literals | ||
3173 | * and are glob-escaped. If this does not match, bash/ash print b\*? | ||
3174 | * - IOW: they "unbackslash" the pattern. | ||
3175 | * Now, look at this: | ||
3176 | * | ||
3177 | * v='\\\*'; echo b$v? | ||
3178 | * | ||
3179 | * The glob pattern is the same here: b\\\*? - an unquoted $var expansion | ||
3180 | * should be used as glob pattern with no changes. However, if glob | ||
3181 | * does not match, bash/ash print b\\\*? - NOT THE SAME as 1st example! | ||
3182 | * | ||
3183 | * ash implements this by having an encoded representation of the word | ||
3184 | * to glob, which IS NOT THE SAME as the glob pattern - it has more data. | ||
3185 | * Glob pattern is derived from it. If glob fails, the decision what result | ||
3186 | * should be is made using that encoded representation. Not glob pattern. | ||
3187 | */ | ||
3188 | |||
3154 | #if ENABLE_HUSH_BRACE_EXPANSION | 3189 | #if ENABLE_HUSH_BRACE_EXPANSION |
3155 | /* There in a GNU extension, GLOB_BRACE, but it is not usable: | 3190 | /* There in a GNU extension, GLOB_BRACE, but it is not usable: |
3156 | * first, it processes even {a} (no commas), second, | 3191 | * first, it processes even {a} (no commas), second, |