framework icon indicating copy to clipboard operation
framework copied to clipboard

Routing error since 4.1

Open xbagir opened this issue 12 years ago • 11 comments

Hi! There is a project route rule: 'preset/{id}.{ext}' and this url: '/preset/1.jpg' In the case of laravel 4.0 segment {id} is equal to "1" And laravel 4.1 segment {id} equals "1.j". It looks like a bug.

xbagir avatar Dec 13 '13 09:12 xbagir

In the meantime you can add a route constraint to your id parameter so that it only matches [0-9]

Anahkiasen avatar Dec 13 '13 09:12 Anahkiasen

@Anahkiasen, your solution is just a monkey patch. Laravel 4.1 breaks back compatability. And i see no sign of this in release docs

xbagir avatar Dec 13 '13 09:12 xbagir

@xbagir while I agree with you being that it does sound like a monkey patch; realistically I would expect Route::pattern('id', '[0-9]+'); to be used in any case, which might be why I haven't noticed this bug :)

carbontwelve avatar Dec 13 '13 09:12 carbontwelve

As the route is probably turned into a regex, the dot will match everything, not just a dot. One way to fix this could be turning the regex generated from {id} to be non-greedy by default.

franzliedke avatar Dec 13 '13 10:12 franzliedke

@xbagir Could you please test whether this patch fixes the issue for you? If it does, I'll send a pull request.

franzliedke avatar Dec 13 '13 10:12 franzliedke

@franzliedke Checked. The patch fixes the problem, thanks!

xbagir avatar Dec 13 '13 11:12 xbagir

Oh, can you please check that it works with a two-digit ID, too?

franzliedke avatar Dec 13 '13 12:12 franzliedke

@franzliedke No, it only works with single digit.

xbagir avatar Dec 13 '13 12:12 xbagir

Darn, I was afraid that would happen. I'll write some tests and come up with a proper fix.

franzliedke avatar Dec 13 '13 12:12 franzliedke

Sent a PR. Test-driven bug fixing is cool. :)

franzliedke avatar Dec 13 '13 13:12 franzliedke

Fixed.

taylorotwell avatar Dec 13 '13 14:12 taylorotwell