Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
uap-universe opened this issue Feb 7, 2024 · 4 comments
Open
Labels

Comments

@uap-universe
Copy link

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

@cxw42
Copy link
Member

cxw42 commented Feb 11, 2024

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!

@uap-universe
Copy link
Author

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

@xuhdev xuhdev added the bug label Feb 18, 2024
@xuhdev
Copy link
Member

xuhdev commented Feb 18, 2024

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.

@uap-universe
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants