PerlDancer / PerlDancer/Dancer2

Routes with mixed inline regexs and tokens

Open
#1,642 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
Perl
Stars
604
Forks
288
Avg merge
1d 5h
Merged PRs (30d)
5

Description

When working on #1641, I planned on adding a test case for get '/(any|some)/thing/:id => sub {...}; to t/classes/Dancer2-Core-Route/match.t, which fails :(

+    [
+        [ 'get', '/(any|some)/thing/:id', sub {61} ],
+        '/some/thing/else',
+        [ { id => 'else', splat => ['some'] }, 61 ]
+    ],

The route matching code extracts the values some and else from the path; but the route regexp only has one regex with a comment. The token assignment iterates through the regex captures starting with those with comments first, assigning the rest to splat. This results in the params { id => 'some', splat => ['else'] } .. which is just wrong.

After some though, I still do not have a way to "fix" this. Creating this issue as a reminder to myself, or in hope someone else may pick it up 🤞 .

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed regression case in t/classes/Dancer2-Core-Route/match.t and reproduce the failure for the mixed inline-regex and token route. Read the token-assignment code in lib/Dancer2/Core/Route.pm around lines 115-141 to understand how captures are assigned. Done means the route maps id to else, keeps some in splat, and the regression test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.