Skip to content

fix: wildcard match does not escape special regex characters#106

Merged
skwasjer merged 1 commit intomainfrom
fix/escape_regex_special_chars
Sep 5, 2024
Merged

fix: wildcard match does not escape special regex characters#106
skwasjer merged 1 commit intomainfrom
fix/escape_regex_special_chars

Conversation

@skwasjer
Copy link
Owner

@skwasjer skwasjer commented Sep 5, 2024

F.ex.:

path/file.jpg?width=* was previously converted to a regex @"^(path/file.jpg?width=).*". This has a few problems:

  • the . (dot) in the filename matches any character in that position, not just the dot.
  • the ? makes the preceding g in jpg an optional character so jp matches just as well. In fact path/file.jpg?width=123 would not actually match because after the optional g, the w is now expected.

All special regex characters are now escaped, iow. the above example would be: @"^(path/file\.jpg\?width=).*"

@skwasjer skwasjer added the bug Something isn't working label Sep 5, 2024
@skwasjer skwasjer force-pushed the fix/escape_regex_special_chars branch from d68c901 to 6bf1eb5 Compare September 5, 2024 22:18
@skwasjer skwasjer enabled auto-merge (squash) September 5, 2024 22:20
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 5, 2024

@skwasjer skwasjer merged commit de01038 into main Sep 5, 2024
@skwasjer skwasjer deleted the fix/escape_regex_special_chars branch September 5, 2024 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant