From 9f0d6f61bc32fb9b174d2a28a40a31d41ccbc83f Mon Sep 17 00:00:00 2001 From: zherczeg Date: Tue, 23 May 2017 15:17:44 +0000 Subject: [PATCH] Use atomic blocks after starstar during conversion. --- src/pcre2_convert.c | 40 ++++++++++++++++++++++++++++++---------- testdata/testinput24 | 14 ++++++++++++++ testdata/testoutput24 | 26 +++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/src/pcre2_convert.c b/src/pcre2_convert.c index 0c2085e..a58a480 100644 --- a/src/pcre2_convert.c +++ b/src/pcre2_convert.c @@ -729,6 +729,8 @@ PCRE2_UCHAR c; BOOL no_backslash = (options & PCRE2_CONVERT_GLOB_NO_BACKSLASH) != 0; 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; @@ -780,6 +782,12 @@ while (pattern < pattern_end) { is_start = pattern == pattern_start + 1; + if (in_atomic) + { + convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS); + in_atomic = FALSE; + } + if (!no_starstar && pattern < pattern_end && *pattern == CHAR_ASTERISK) { if (!is_start && pattern[-2] != separator) @@ -814,6 +822,7 @@ while (pattern < pattern_end) } pattern++; + after_starstar = TRUE; if (is_start) { @@ -825,7 +834,7 @@ while (pattern < pattern_end) out.out_str[5] = CHAR_VERTICAL_LINE; convert_glob_write_str(&out, 6); - convert_glob_print_wildcard(&out, separator, with_escape); + convert_glob_print_separator(&out, separator, with_escape); convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS); continue; } @@ -875,7 +884,18 @@ while (pattern < pattern_end) } if (!is_start) - convert_glob_print_commit(&out); + { + if (after_starstar) + { + out.out_str[0] = CHAR_LEFT_PARENTHESIS; + out.out_str[1] = CHAR_QUESTION_MARK; + out.out_str[2] = CHAR_GREATER_THAN_SIGN; + convert_glob_write_str(&out, 3); + in_atomic = TRUE; + } + else + convert_glob_print_commit(&out); + } if (no_wildsep) convert_glob_write(&out, CHAR_DOT); @@ -923,19 +943,19 @@ while (pattern < pattern_end) if (result == 0 || result == ERROR_NO_SLASH_Z) { - if (result == ERROR_NO_SLASH_Z) - { - convert_glob_write(&out, CHAR_NULL); - result = 0; - } - else + if (result == 0) { out.out_str[0] = CHAR_BACKSLASH; out.out_str[1] = CHAR_z; - out.out_str[2] = CHAR_NULL; - convert_glob_write_str(&out, 3); + convert_glob_write_str(&out, 2); } + if (in_atomic) + convert_glob_write(&out, CHAR_RIGHT_PARENTHESIS); + + convert_glob_write(&out, CHAR_NULL); + result = 0; + if (!dummyrun && out.output_size != (PCRE2_SIZE) (out.output - use_buffer)) result = PCRE2_ERROR_NOMEMORY; } diff --git a/testdata/testinput24 b/testdata/testinput24 index 7cba4aa..282b697 100644 --- a/testdata/testinput24 +++ b/testdata/testinput24 @@ -245,6 +245,20 @@ /abc\/**\/abc/ +/**\/*a*b*g*n*t/ + abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt + +/**\/*a*\/**/ + xx/xx/xx/xax/xx/xb + +/**\/*a*/ + xx/xx/xx/xax + xx/xx/xx/xax/xx + +/**\/*a*\/**\/*b*/ + xx/xx/xx/xax/xx/xb + xx/xx/xx/xax/xx/x + #pattern convert=glob:glob_no_starstar /***/ diff --git a/testdata/testoutput24 b/testdata/testoutput24 index 5884f99..9c5466d 100644 --- a/testdata/testoutput24 +++ b/testdata/testoutput24 @@ -367,7 +367,7 @@ No match (?s) /**\/abc/ -(?s)(?:\A|[^/])abc\z +(?s)(?:\A|/)abc\z /abc\/**/ (?s)\Aabc/ @@ -375,6 +375,30 @@ No match /abc\/**\/abc/ (?s)\Aabc/(*COMMIT)(?:.*?/)??abc\z +/**\/*a*b*g*n*t/ +(?s)(?:\A|/)(?>[^/]*?a)(?>[^/]*?b)(?>[^/]*?g)(?>[^/]*?n)(?>[^/]*?t\z) + abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt + 0: /abcdefghijklmnop.txt + +/**\/*a*\/**/ +(?s)(?:\A|/)(?>[^/]*?a)(?>[^/]*?/) + xx/xx/xx/xax/xx/xb + 0: /xax/ + +/**\/*a*/ +(?s)(?:\A|/)(?>[^/]*?a)(?>[^/]*?\z) + xx/xx/xx/xax + 0: /xax + xx/xx/xx/xax/xx +No match + +/**\/*a*\/**\/*b*/ +(?s)(?:\A|/)(?>[^/]*?a)(?>[^/]*?/)(*COMMIT)(?:.*?/)??(?>[^/]*?b)(?>[^/]*?\z) + xx/xx/xx/xax/xx/xb + 0: /xax/xx/xb + xx/xx/xx/xax/xx/x +No match + #pattern convert=glob:glob_no_starstar /***/