Code Monkey home page Code Monkey logo

Comments (10)

necmettin avatar necmettin commented on July 29, 2024

It should be more than that IMHO. Anything that is not a control character should be usable maybe?

from router.

bramus avatar bramus commented on July 29, 2024

I see that Laravel uses '/\{(.*?)\}/' as the pattern to extract parameters.

I'll gladly accept a PR containing the change (+ accompanying tests) :-)

from router.

fscchan avatar fscchan commented on July 29, 2024

I propose to change the line 341-344

$route['pattern'] = preg_replace('/{([A-Za-z]*?)}/', '(\w+)', $route['pattern']);

if (preg_match_all('#^'.$route['pattern'].'$#', $uri, $matches, PREG_OFFSET_CAPTURE)) {

to

$route['pattern'] = preg_replace('/(?![\]p){([A-Za-z]*?)}/', '(\w+)', $route['pattern']);

if (preg_match_all('#^'.$route['pattern'].'$#u', $uri, $matches, PREG_OFFSET_CAPTURE)) {

So that the router allow all unicode characters character class \p{L} according to https://stackoverflow.com/a/38938931

from router.

fscchan avatar fscchan commented on July 29, 2024

Apparently $_SERVER["REQUEST_URI"] encodes non-latin and symbols to RFC-3986 and needs to be decoded before the route matching.

from router.

bramus avatar bramus commented on July 29, 2024

I've just pushed some things to master. Looking forward to your feedback.

The problem here was twofold:

  1. Support for Cyrillic/astral/etc. Symbols in route pattern values (e.g. make it so that /hello/πŸ’© matches the route pattern /hello/{name})
  2. Support for Cyrillic/astral/etc. Symbols in route placeholder names (e.g. make it so that /hello/bramus matches the route pattern /hello/{ΠΈΠΌΠ΅})

I've done two separate commits to tackle this:

  1. Support for Cyrillic/astral/etc. Symbols in route pattern values: 0f4733d
  2. Support for Cyrillic/astral/etc. Symbols in route placeholder names: ae0db20

Feel free to test this from dev-master (Circle CI says all is fine). If well received I'll tag it as a new release.

from router.

fscchan avatar fscchan commented on July 29, 2024

I might have misunderstood this issue. I thought it was about supporting unicode characters on the route itself.

My bad.

from router.

bramus avatar bramus commented on July 29, 2024

@fscchan Yeah, that was my first impression too. Took me a while to notice that the original poster was adjusting the regex part for the placeholders (e.g. {var} in a route pattern).

While I was at it, I thought I'd just fix both cases ;)

from router.

bramus avatar bramus commented on July 29, 2024

FYI: Version 1.4 got tagged and released.

from router.

notom avatar notom commented on July 29, 2024

Yes! That worked.
Just one more thing: somewhere in getCurrentUri function the text should be urldecode-ed

from router.

bramus avatar bramus commented on July 29, 2024

Will take a look into it.

from router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.