Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

odd behaviour on reroute and handling of %20 in text params

30 views
Skip to first unread message

Jean Fabre

unread,
Oct 20, 2024, 9:54:31 AM10/20/24
to Fat-Free Framework
Hi,

A bit desperate here because I can't seem to understand what's wrong.

I am rerouting a url based on a params passed.

in the param, I have a truncated url, containing for example %2FCustom%20Packages%2F

%2Fis treated properly and ends up as a /

but %20 ends up as %2520 ...

Can't seems to work it out. can I setup f3 to treat this properly and have a space character for the url reroute?

the concrete case is as follow:


the url above goes through a fat free code, it takes the file param, and reroute to a github link that should look like:


notice in the path, Ihave a folder 'Custom Packages' band the space ends up as %2520 like so


any help or advice is welcome.

Thanks!

Jean


ved

unread,
Oct 20, 2024, 10:03:48 AM10/20/24
to Fat-Free Framework
Hi, 

But it would be useful if you posted some of your code doing the parsing and rerouting.

Cheers

Jean Fabre

unread,
Oct 20, 2024, 10:17:10 AM10/20/24
to Fat-Free Framework
Hi,

Thanks for the quick reply,

url encoding affects everything, here the issue seems to only affect the space... which is very odd:

here's the code:

$f3->route('GET /download',
    function($f3,$params) {

    $url = "http://raw.github.com/".$_GET['repository']."/master/".$_GET['file'];

    $f3->reroute($url);

    }
);


thanks,

Jean

ved

unread,
Oct 20, 2024, 11:10:28 AM10/20/24
to Fat-Free Framework
Hi,

I ran some tests on my end and the issue seems to be that you're concatenating "/master/" when you should be concatenating "/master".
(If not, github does indeed give 404 and turns the space into %2520, which according to this article, is a double encoded space)

So, the correct string would be:

$url = "http://raw.github.com/".$_GET['repository']."/master".$_GET['file'];

Cheers :-)

ved

unread,
Oct 20, 2024, 11:15:29 AM10/20/24
to Fat-Free Framework
PS: I should say that I copied your url from your first post, where the "file" parameter already starts with a slash. 

The rest of your examples do not exhibit the double slash issue but that's what I got when testing.

I was getting:


Cheers

Jean Fabre

unread,
Oct 20, 2024, 11:16:29 AM10/20/24
to Fat-Free Framework
Hi,

ok, found the issue... if the parameter starts with / it bugs, if it doesn't it works... how odd...

If there is an explanation, I am all ear :) else, I'll treat it as a "feature" :)

Bye,

Jean

ved

unread,
Oct 20, 2024, 11:23:23 AM10/20/24
to Fat-Free Framework
Hi,

See my reply above, it's a bug on your code.

You're concatenating the string "/master/" which already has a trailing slash, with the file parameter that starts with a slash, so you end up with double slashes, which causes the issue.

If you know that the file parameter will always start with a slash, then simple removing the trailing slash from the concatenation as I exemplified should work.
If not, you'll have to run some checks and see if the file parameter starts or not with a slash and act accordingly.

Cheers

On Sunday, October 20, 2024 at 4:16:29 PM UTC+1 Jean Fabre wrote

Jean Fabre

unread,
Oct 20, 2024, 11:30:33 AM10/20/24
to Fat-Free Framework
Hi,

 yes, you are right! thanks for looking into this! I figured it out on my end too after messing with it.

the odd thing is worked as is for almost 7 years and started to bug only now.... the double / should not affect ( though it's a mistake on my end obvivously)

Thanks again!!

Jean
Reply all
Reply to author
Forward
0 new messages