skipperbent / simple-php-router

Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
647 stars 121 forks source link

Bad Request error when url's parameters contain "%" using regex #635

Closed cdanielzt closed 1 year ago

cdanielzt commented 1 year ago
Route::get('/addon/{name}/{apikey}', function($name, $apikey){

    return response()->redirect("addons/addons.php?addon=$name&apikey=$apikey");

})->where(['apikey' => '[\w\-\@\%]+' ]);

On this route i got an Bad Request error when the apikey parameter contains '%' like /addon/communitymap/bjV%3DN3n2e4nu.

I would like the parameter to accept letters, numbers and these symbols % @ _ -

The regex works for any other symbol rather than %

In summary:

This works: /addon/communitymap/bjVQ@XlSUkBhZmM

This don't work: /addon/communitymap/bjVQ@XlSUkBh%ZmM /addon/communitymap/bjVQ%XlSUkBh%ZmM

cdanielzt commented 1 year ago

I have fixed it by adding \= to the accepted characters

DeveloperMarius commented 1 year ago

Hey,

yes, this is the correct way. You have to escape some characters in a RegEx.

~ Marius