routes.js icon indicating copy to clipboard operation
routes.js copied to clipboard

Global search in regex

Open rikukissa opened this issue 10 years ago • 1 comments

There's still actually one problem with this one. For example if I have a refex /a/g and the path we are matching it against is aaa then the splats params should be ["a", "a", "a"].

Now the match function actually starts looping through captures from the second element so the first match is omitted.

for (var j = 1, len = captures.length; j < len; ++j) {

So basically looping should start from the first element if the given regex is global.

Everything else would break if we just changed the looping start point. One solution would do something like this

var j = re.global ? 0 : 1;
for (j, len = captures.length; j < len; ++j) {

Any thoughts on this? I'd be happy to create a new pull request with couple of new tests included and version number changed to 1.2.1.

PS. It's nice to see that you are responding to pull requests almost immediately!

rikukissa avatar Jul 21 '14 19:07 rikukissa

I understand what you mean, you would want to to have all the global captures starting from index 0.

This seems fine.

However that is a backwards compat change from the exec global semantics. So we should bump major version number. In fact i should have bumped major before instead of minor.

Let's add some more tests for this. I also really need to jump into the tests and use upgrade them to tape.

Raynos avatar Jul 21 '14 20:07 Raynos