diff --git a/src/pcre2_convert.c b/src/pcre2_convert.c index 1d055f8..ea99556 100644 --- a/src/pcre2_convert.c +++ b/src/pcre2_convert.c @@ -616,7 +616,9 @@ prev_c = 0; if (*pattern == CHAR_RIGHT_SQUARE_BRACKET) { - convert_glob_write(out, CHAR_RIGHT_SQUARE_BRACKET); + out->out_str[0] = CHAR_BACKSLASH; + out->out_str[1] = CHAR_RIGHT_SQUARE_BRACKET; + convert_glob_write_str(out, 2); has_prev_c = TRUE; prev_c = CHAR_RIGHT_SQUARE_BRACKET; pattern++; @@ -777,8 +779,8 @@ BOOL no_wildsep = (options & PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR) != 0; BOOL no_starstar = (options & PCRE2_CONVERT_GLOB_NO_STARSTAR) != 0; BOOL in_atomic = FALSE; BOOL after_starstar = FALSE; -BOOL with_escape, is_start; -int result, len; +BOOL with_escape, is_start, after_separator; +int result; (void)utf; /* Avoid compiler warning. */ @@ -840,11 +842,7 @@ while (pattern < pattern_end) if (!no_starstar && pattern < pattern_end && *pattern == CHAR_ASTERISK) { - if (!is_start && pattern[-2] != separator) - { - result = PCRE2_ERROR_CONVERT_SYNTAX; - break; - } + after_separator = is_start || (pattern[-2] == separator); do pattern++; while (pattern < pattern_end && *pattern == CHAR_ASTERISK); @@ -855,27 +853,16 @@ while (pattern < pattern_end) break; } - if (escape != 0 && *pattern == escape) - { - pattern++; - if (pattern >= pattern_end) - { - result = PCRE2_ERROR_CONVERT_SYNTAX; - break; - } - } - - if (*pattern != separator) - { - result = PCRE2_ERROR_CONVERT_SYNTAX; - break; - } - - pattern++; after_starstar = TRUE; + if (after_separator && escape != 0 && *pattern == escape && + pattern + 1 < pattern_end && pattern[1] == separator) + pattern++; + if (is_start) { + if (*pattern != separator) continue; + out.out_str[0] = CHAR_LEFT_PARENTHESIS; out.out_str[1] = CHAR_QUESTION_MARK; out.out_str[2] = CHAR_COLON; @@ -886,32 +873,39 @@ while (pattern < pattern_end) convert_glob_print_separator(&out, separator, with_escape); convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS); + + pattern++; continue; } convert_glob_print_commit(&out); + if (!after_separator || *pattern != separator) + { + out.out_str[0] = CHAR_DOT; + out.out_str[1] = CHAR_ASTERISK; + out.out_str[2] = CHAR_QUESTION_MARK; + convert_glob_write_str(&out, 3); + continue; + } + out.out_str[0] = CHAR_LEFT_PARENTHESIS; out.out_str[1] = CHAR_QUESTION_MARK; out.out_str[2] = CHAR_COLON; out.out_str[3] = CHAR_DOT; out.out_str[4] = CHAR_ASTERISK; out.out_str[5] = CHAR_QUESTION_MARK; - len = 6; - if (with_escape) - { - out.out_str[6] = CHAR_BACKSLASH; - len = 7; - } + convert_glob_write_str(&out, 6); - convert_glob_write_str(&out, len); + convert_glob_print_separator(&out, separator, with_escape); - out.out_str[0] = (uint8_t) separator; - out.out_str[1] = CHAR_RIGHT_PARENTHESIS; + out.out_str[0] = CHAR_RIGHT_PARENTHESIS; + out.out_str[1] = CHAR_QUESTION_MARK; out.out_str[2] = CHAR_QUESTION_MARK; - out.out_str[3] = CHAR_QUESTION_MARK; - convert_glob_write_str(&out, 4); + convert_glob_write_str(&out, 3); + + pattern++; continue; } diff --git a/testdata/testinput24 b/testdata/testinput24 index f96e4cc..69fa366 100644 --- a/testdata/testinput24 +++ b/testdata/testinput24 @@ -252,6 +252,9 @@ /****/ /**\/abc/ + abc + x/abc + xabc /abc\/**/ @@ -271,6 +274,19 @@ xx/xx/xx/xax/xx/xb xx/xx/xx/xax/xx/x +"**a"convert=glob + a + c/b/a + c/b/aaa + +"a**/b"convert=glob + a/b + ab + +"a/**b"convert=glob + a/b + ab + #pattern convert=glob:glob_no_starstar /***/ diff --git a/testdata/testoutput24 b/testdata/testoutput24 index 9b4c11f..dd0f1bc 100644 --- a/testdata/testoutput24 +++ b/testdata/testoutput24 @@ -41,7 +41,7 @@ # Now some actual tests /a?b[]xy]*c/ -(?s)\Aa[^/]b[]xy](*COMMIT)[^/]*?c\z +(?s)\Aa[^/]b[\]xy](*COMMIT)[^/]*?c\z azb]1234c 0: azb]1234c @@ -143,15 +143,15 @@ No match 0: ten /a[]]b/ -(?s)\Aa[]]b\z +(?s)\Aa[\]]b\z a]b 0: a]b /a[]a-]b/ -(?s)\Aa[]a\-]b\z +(?s)\Aa[\]a\-]b\z /a[]-]b/ -(?s)\Aa[]\-]b\z +(?s)\Aa[\]\-]b\z a-b 0: a-b a]b @@ -161,7 +161,7 @@ No match No match /a[]a-z]b/ -(?s)\Aa[]a-z]b\z +(?s)\Aa[\]a-z]b\z aab 0: aab @@ -343,10 +343,10 @@ No match (?s)\A[^/]a[^/]/[^/]b[^/]\z /[a\\b\c][]][-][\]\-]/ -(?s)\A[a\\bc][]][\-][\]\-]\z +(?s)\A[a\\bc][\]][\-][\]\-]\z /[^a\\b\c][!]][!-][^\]\-]/ -(?s)\A[^/a\\bc][^/]][^/\-][^/\]\-]\z +(?s)\A[^/a\\bc][^/\]][^/\-][^/\]\-]\z /[[:alpha:][:xdigit:][:word:]]/ (?s)\A[[:alpha:][:xdigit:][:word:]](?