Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias()/reroute() and params requiring proper urlencode() #345

Closed
kumy opened this issue Jun 11, 2022 · 1 comment
Closed

alias()/reroute() and params requiring proper urlencode() #345

kumy opened this issue Jun 11, 2022 · 1 comment
Labels

Comments

@kumy
Copy link
Contributor

kumy commented Jun 11, 2022

I think there is a problem with alias()/reroute() function when it build the url using known parameter from current request, and when a parameter need to be url encoded.

Actual result
An "invalid" url as it doesn't properly use urlencode() on the url parameters

ex:

  • input: /a/bar%25
  • output: /a/bar% <- the percent sign is not encoded

Expected result
A valid url show be generated, with the parameter properly encoded

ex:

  • input: /a/bar%25
  • output: /a/bar%25

Step to reproduce
I've extracted this part of code to reproduce the issue:

<?php

require __DIR__.'/../../vendor/autoload.php';

$f3 = \Base::instance();
$f3->route('GET /a/@foo',
    function(\Base $f3, $params) {
        echo 'Input params:'.PHP_EOL;
        var_dump($params);

        echo PHP_EOL.'Generated url:'.PHP_EOL;
        var_dump($f3->alias('alias1'));
        $f3->reroute('@alias1');
    }
);
$f3->route('GET @alias1: /b/@foo',
    function(\Base $f3, $params) {
        var_dump($params);
    }
);

$f3->run();
$ curl "https://xxxxx/a/bar%25" 
Input params:
array(2) {
  [0]=>
  string(7) "/a/bar%"
  ["foo"]=>
  string(4) "bar%"
}

Generated url:
string(7) "/b/bar%"  // <- missing properly encoding
$ curl "https://xxxxx/a/baz%25" -v 2>&1 |grep -i loca
< location: https://xxxxx/b/baz%
$ curl "https://xxxxx/a/baz%25" -L
curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)

Notes
I had the expected result if I use urlencode() inthe return statements of the anonymous function inside the build() function.

@ikkez
Copy link
Member

ikkez commented Sep 13, 2022

should be fixed in latest commit. unit test added at f3-factory/fatfree-dev@1093950

ikkez added a commit that referenced this issue Sep 13, 2022
@ikkez ikkez closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants