path-to-regexp icon indicating copy to clipboard operation
path-to-regexp copied to clipboard

Invalid regex patterns not properly detected.

Open Lord-Kamina opened this issue 3 years ago • 2 comments

I've noticed, due to how the lexer is written, it's not particularly difficult to make invalid patterns that won't be detected as being erroneous, specifically when ')' appears at weird locations.

Routes such as "/:foo([123]+))", or "/:foo)([123]+)" should give an error, but they don't.

Lord-Kamina avatar Oct 13 '22 20:10 Lord-Kamina

It's not particularly difficult to add that to detect if you want to open a PR, but it'd have to be part of a new major release since it's a breaking change for anyone potentially using these patterns for whatever reason.

blakeembrey avatar Oct 14 '22 05:10 blakeembrey

It's not particularly difficult to add that to detect if you want to open a PR, but it'd have to be part of a new major release since it's a breaking change for anyone potentially using these patterns for whatever reason.

I'm toying around with having a boolean character_class that is set to true when an unescaped [ is found and back to false when a ] is found. My idea would be to treat brackets as groups only when this switch is on; then a check for ) could give an error. Not entirely sure of what other repercussions this can have though, so I won't commit anything for now.

Lord-Kamina avatar Oct 19 '22 10:10 Lord-Kamina