Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

You can't use wildcards and name matching at the same time #514

Closed
JohanSpade opened this Issue · 6 comments

4 participants

@JohanSpade

Just starting out with dancer2 and it appears this works

get '/foo/*' => sub {...}; 
get '/foo/:bar' => sub {...}; 

But the following all throw a error at me

get '/foo/:bar/*' => sub {...};
get '/foo/*/:bar' => sub {...};

The error is
Internal Server Error
Use of uninitialized value within @splat_or_megasplat in pattern match (m//) at /usr/local/share/perl5/Dancer2/Core/Route.pm line 101.

@lustremedia

Same issue here! Is there any explanation why this is so?

@DavsX DavsX referenced this issue from a commit in DavsX/Dancer2
@kovdavid kovdavid Corrected issue #514
Corrected #514 by adding a check for definedness of a condition in an if
statement
b80055e
@DavsX

#642 this fixes the error (hopefully)

@DavsX

But the issue remains. For route handler like this:
get '/foo/*/:name' => sub { param('name') };
it will return for path '/foo/something/davs' the string 'something' instead of 'davs'. Question is if it is an issue, or it makes no sense to use wildcard and named match in this configuration

A possible solution is to handle splats and megasplats the same way i.e. putting them into an array (as megasplats are currently being handled) and when it comes to assigning values to named matches we could just use the non-array values.

For route: "/ASTERISK_GOES_HERE/:name/**" the path '/foo/bar/baz/baz2/baz3' is parsed into ('foo', 'bar', ['baz','baz2','baz3']) and because of that, 'foo' would be put into :name.
My suggestion would be to parse it like this: (['foo'], 'bar', ['baz','baz2','baz3']) and when it comes to assigning values to named matches, only use non-array values, so :name would get the value 'bar'. Notice how 'foo' is in an array, just like a megasplat is.

Opinions?

Edit: sry, github messed up my route, it should be /asterisk/colonname/asteriskasterisk

@lustremedia

@DavsX
My opionion:
Maybe it would be best to only allow splat or megasplat at the end of routes when named routing is used: e.g.

/foo/:bar/:baz/* or /foo/:bar/**

For /foo/:bar/:baz/* called with /foo/bar/baz/baz2 you would get ('foo', 'bar', 'baz',['baz2'])
For /foo/:bar/** called with /foo/bar/baz/baz2/baz3 you would get ('foo', 'bar', ['baz','baz2','baz3'])

What's more important though is Documentation. A "Do not to mix wildcard and named routing" would save people some headache and time.

@DavsX

Yeah after further investigation with the route matching regex as currently is there is no way of telling that which match is splat is which is not (only the fact is checked, if the regex itself contains the comment (mega)splat, not the fact that where), so I'd say that they should not be mixed, or rather named matches should NOT be AFTER the wildcards.

@veryrusty veryrusty referenced this issue from a commit
@veryrusty veryrusty Rework route match for mixed token and splat captures.
With all the regex captures now flagged with comments, we iterate over
the captured values knowing if they were from a token, splat or megasplat.

Added examples of mixed token ans splat capture to the route matching
tests.

Resolves #514.
3ac0969
@veryrusty veryrusty closed this issue from a commit
@veryrusty veryrusty Rework route match for mixed token and splat captures.
With all the regex captures now flagged with comments, we iterate over
the captured values knowing if they were from a token, splat or megasplat.

Added examples of mixed token ans splat capture to the route matching
tests.

Resolves #514.
36b77a1
@veryrusty veryrusty closed this in 36b77a1
@xsawyerx
Owner

Resolved by #729.

Thanks! :+1:

@xsawyerx xsawyerx referenced this issue from a commit
@xsawyerx xsawyerx v0.154000
    [ BUG FIXES ]
    * GH #744: Serialize anything, not just references. (Sawyer X)
    * GH #744: Serialize regardless of content_type of serializer. (Sawyer X)
    * GH #764: Catch template render errors. (Russell Jenkins, Steven Humphrey)
    * Calling uri_for(undef) doesn't crash. (Sawyer X)
    * GH #732: Correct name for 403 (Forbidden, not Unauthorized).
      (Theo van Hoesel, Sawyer X, Mickey Nasriachi, Omar M. Othman)
    * GH #753: Syntax of parameterized types. (Russell Jenkins)
    * GH #734: Failing tests on Windows. (Russell Jenkins, Sawyer X)

    [ ENHANCEMENTS ]
    * GH #664, #684, #715: Handler::File replaced for static files with
      Plack::Middleware::Static, allowing files to be served *before* routes.
      This means hooks do not apply to static files anymore!
      (Russell Jenkins, DavsX)
    * Engines now have "logger" attribute to log errors. It sends the
      Dancer2::Logger:: object, if one exists. (Sawyer X)
    * Serializers do not need to implement "loaded" method. (Sawyer X)
    * GH #733: In core: response_xxx removed in favor of generic
      standard_response. (Sawyer X, Mickey Nasriachi, Omar M. Othman)
    * GH #514, #642, #729: Allow mixing named params, splat, and
      megasplat. (Russell Jenkins, Johan Spade, Dávid Kovács)
    * GH #596: no_server_tokens works, as well as DANCER_NO_SERVER_TOKENS.
      (Omar M. Othman, Sawyer X, Mickey Nasriachi)
    * GH #639: Validate engine types in configuration.
      (Sawyer X, Omar M. Othman, Mickey Nasriachi, Russell Jenkins)
    * GH #663, #741: Remove "accept_type" attribute and other references.
      (Mickey Nasriachi, Theo van Hoesel)
    * GH #748: Provide forwarded_host, forwarded_protocol. (Sawyer X)
    * GH #748: Do not provide a default env, require env for a request.
      (Sawyer X)
    * GH #742: Update test skeleton to use to_app. (Dávid Kovács)
    * GH #636: Use Plack::Test in more tests. (Dávid Kovács)

    [ DOCUMENTATION ]
    * GH #656: Dancer2::Manual::Testing as a guide for testing Dancer2
      applications. (Sawyer X)
    * Improved documentation of route matching. (Russell Jenkins)
    * Migration document update relating to enhancements.
      (Sawyer X, Mickey Nasriachi)
    * GH #731: Document changes in session.
      (racke, Sawyer X, Mickey Nasriachi, Omar M. Othman)
    * Document "id" attribute in Request object. (Sawyer X)
    * Correct Cookbook examples on command line scripts. (Sawyer X)
775ff73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.