editorconfig/editorconfig-core-c

Bug: Star is not treated as a literal character inside brackets

Opened this issue · 4 comments

The reference implementation does not treat a '*' character as a literal character inside brackets.

Current behavior

pattern = "ab[e*]cd.i";
  
// matches:
"ab[e]cd.i"
"ab[[]cd.i"
"ab[^]cd.i"
"ab[/]cd.i"
"ab[[]cd.i"
"ab[e[^/e[e]cd.i"

// does not match:
"abecd.i"
"ab*cd.i"

Expected behavior

the opposite

Thanks for reporting! Would you please post instructions for reproducing the issue? Please make sure to include the specific commit at which you are testing. Much appreciated!

I am testing against master branch by invoking ec_glob(pattern, string) with the pattern and the test strings from above.

I think this is a bug, as there's really no meaning * in brackets. We really tried to mimic gitignore patterns in the beginning, and my experiment shows that gitignore would see * as a literal inside brackets. Also checked out PCRE, same behavior.

I think this is also what the spec means, but we didn't write it clearly out.

Yes, I agree. There is another thing the spec does not clearly write out: slashes have precedence over anything else.

Meaning that a slash will "destroy" the bracket pattern.

Example: [ab/cd] will not be translated as "one of a, b, /, c, or d" but instead it will be the literal sequence [ab/cd].

See also issue 499 in the main repo.

and you might also be interested in how I solved this.

However, since this looks very intentional, I think it's desired behavior - just not documented. So when fixing this bug, you might need to be careful not to change this behavior.