Skip to content

fix: do not treat lookbehinds as named capture groups - #212

Open
vns-agm wants to merge 2 commits into
pillarjs:masterfrom
vns-agm:fix-lookbehind-group-keys
Open

vns-agm wants to merge 2 commits into
pillarjs:masterfrom
vns-agm:fix-lookbehind-group-keys

Conversation

@vns-agm

@vns-agm vns-agm commented Oct 21, 2026

Copy link
Copy Markdown

Fixes #211

MATCHING_GROUP_REGEXP reads (?<= and (?<! as the start of a named group, so the text up to the next > became the key name. Routes like /(?<=\/f\/)(?<id>[0-9]+)$/ got a key such as =\/f\/)(?<id instead of id, and if an unnamed group came after the lookbehind there were fewer keys than groups, so key.name threw and the request ended in a 500.

A group name can't start with = or !, so the name pattern now excludes them ([^=!>][^>]*). Lookbehinds are then skipped like other (? groups.

Tests: added two cases to test/route.js (two lookbehind routes with a named group, and a lookbehind followed by an unnamed and a named group). Existing named/unnamed group behaviour is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RegExp route with a lookbehind before a named group gets a wrong param key or a 500

1 participant