From cc27cf48fdb55f7f50d7d512143036476066fa4d Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 14 Jul 2016 09:34:42 +0000 Subject: [PATCH] Back out non-collating [a-z] ranges. Instead of changing the whole course to another POSIX-permitted way for consistency and uniformity I decide to completely ignore missing regex fucntionality and focus on fixing bugs in what we have now, too many small obstacles we have choicing other way, counting ports. Corresponding libc changes are backed out in r302824. --- bin/sh/expand.c | 15 ++++++++++++++- bin/sh/tests/builtins/case7.0 | 7 ++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/sh/expand.c b/bin/sh/expand.c index 25864bae13a2..6d0d78a398df 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -107,6 +107,7 @@ static void expmeta(char *, char *, struct arglist *); static int expsortcmp(const void *, const void *); static int patmatch(const char *, const char *); static void cvtnum(int, char *); +static int collate_range_cmp(wchar_t, wchar_t); void emptyarglist(struct arglist *list) @@ -137,6 +138,16 @@ appendarglist(struct arglist *list, char *str) list->args[list->count++] = str; } +static int +collate_range_cmp(wchar_t c1, wchar_t c2) +{ + static wchar_t s1[2], s2[2]; + + s1[0] = c1; + s2[0] = c2; + return (wcscoll(s1, s2)); +} + static char * stputs_quotes(const char *data, const char *syntax, char *p) { @@ -1348,7 +1359,9 @@ patmatch(const char *pattern, const char *string) return 0; } else wc2 = (unsigned char)*p++; - if (wc <= chr && chr <= wc2) + if ( collate_range_cmp(chr, wc) >= 0 + && collate_range_cmp(chr, wc2) <= 0 + ) found = 1; } else { if (chr == wc) diff --git a/bin/sh/tests/builtins/case7.0 b/bin/sh/tests/builtins/case7.0 index 54db93d8ceb6..96b9de66fe27 100644 --- a/bin/sh/tests/builtins/case7.0 +++ b/bin/sh/tests/builtins/case7.0 @@ -14,6 +14,11 @@ c1=e c2=$(printf '\366') case $c1$c2 in -[a-z][!a-z]) ;; +[a-z][a-z]) ;; +*) echo wrong at $LINENO ;; +esac + +case $c1$c2 in +[a-f][n-p]) ;; *) echo wrong at $LINENO ;; esac