Support the general case of starstar in glob conversion.

This commit is contained in:
Zoltán Herczeg 2017-05-24 15:22:03 +00:00
parent 9826db624e
commit 0b2052f714
3 changed files with 84 additions and 45 deletions

View File

@ -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;
}

16
testdata/testinput24 vendored
View File

@ -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
/***/

47
testdata/testoutput24 vendored
View File

@ -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:]](?<!/)\z
@ -389,6 +389,12 @@ No match
/**\/abc/
(?s)(?:\A|/)abc\z
abc
0: abc
x/abc
0: /abc
xabc
No match
/abc\/**/
(?s)\Aabc/
@ -420,6 +426,29 @@ No match
xx/xx/xx/xax/xx/x
No match
"**a"convert=glob
(?s)a\z
a
0: a
c/b/a
0: a
c/b/aaa
0: a
"a**/b"convert=glob
(?s)\Aa(*COMMIT).*?/b\z
a/b
0: a/b
ab
No match
"a/**b"convert=glob
(?s)\Aa/(*COMMIT).*?b\z
a/b
0: a/b
ab
No match
#pattern convert=glob:glob_no_starstar
/***/
@ -438,7 +467,7 @@ No match
(?s)a
/**a**/
** Pattern conversion error at offset 2: invalid syntax
(?s)a
/a*b/
(?s)\Aa(*COMMIT).*?b\z
@ -456,7 +485,7 @@ No match
(?s)\Aa\\b\\cd\z
/**\/a/
** Pattern conversion error at offset 2: invalid syntax
(?s)\\/a\z
/a`*b/convert_glob_escape=`
(?s)\Aa\*b\z