aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 6b910569f..179155f66 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -6466,6 +6466,19 @@ static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p)
6466/* ${var/[/]pattern[/repl]} helpers */ 6466/* ${var/[/]pattern[/repl]} helpers */
6467static char *strstr_pattern(char *val, const char *pattern, int *size) 6467static char *strstr_pattern(char *val, const char *pattern, int *size)
6468{ 6468{
6469 if (!strpbrk(pattern, "*?[\\")) {
6470 /* Optimization for trivial patterns.
6471 * Testcase for very slow replace (performs about 22k replaces):
6472 * x=::::::::::::::::::::::
6473 * x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;echo ${#x}
6474 * echo "${x//:/|}"
6475 */
6476 char *found = strstr(val, pattern);
6477 if (found)
6478 *size = strlen(pattern);
6479 return found;
6480 }
6481
6469 while (1) { 6482 while (1) {
6470 char *end = scan_and_match(val, pattern, SCAN_MOVE_FROM_RIGHT + SCAN_MATCH_LEFT_HALF); 6483 char *end = scan_and_match(val, pattern, SCAN_MOVE_FROM_RIGHT + SCAN_MATCH_LEFT_HALF);
6471 debug_printf_varexp("val:'%s' pattern:'%s' end:'%s'\n", val, pattern, end); 6484 debug_printf_varexp("val:'%s' pattern:'%s' end:'%s'\n", val, pattern, end);