Strange regex compilation in routes #1162

Closed
davidmurdoch opened this Issue Jun 6, 2012 · 4 comments

Projects

None yet

2 participants

Express 2.5.9 using app.all(string, function).

The route:
":ids(x(y|z)+)"

incorrectly compiles to:
/^(?:(x(y|z))+)\/?$/i

The plus operator should be applied to only (y|z), but the operator applies to x(y|z) in its entirety.

Owner
tj commented Jun 6, 2012

ah - yeah that's from the non-greedy paren match. i dont think you can express balanced matches with js regexps, we would have to fiddle with the string

I found that wrapping the inner matching group and plus operator with another set of parenthesis fixes it (sorta). I'd love to take a stab at fixing it. Off the top of your head...any idea where I the offending code would be?

Owner
tj commented Jun 6, 2012

it's in the utils.js file, there's a method that converts a string to a regexp

I hacked a parser together and some tests: http://jsfiddle.net/musicisair/PdaHh/

It's a hideous "solution" and probably insanely slow, but it passes the tests.

I don't have time to optimize it ... but if someone wants to for me please feel free. :-)

@tj tj closed this Jun 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment