fusio icon indicating copy to clipboard operation
fusio copied to clipboard

Problem with URL and unicode characters

Open christiaanvaken opened this issue 3 years ago • 6 comments

Hi there,

I have a PHP script created in Fusio which gets parameters from the URL and uses those to query a database. There is only an issue with the client which is sending the & and = characters as ASCII code. Is there a way to replace those ASCII codes to the right characters before I use the getParameter funtion?

Here an example of the code: $http_rule = $request->getParameter('value'); $http_code = $request->getParameter('status'); $http_protocol = $request->getParameter('protocol');

The client sends the URL as follows: GET /test/lookup?value=31103%26status%3D402%26protocol%3DGET

christiaanvaken avatar Feb 18 '22 10:02 christiaanvaken

Hi, so you could simply use the urldecode function of PHP to decode those values. But is there maybe a problem on the client side since the decoded value looks more correct s. /test/lookup?value=value=31103&status=402&protocol=

chriskapp avatar Feb 18 '22 18:02 chriskapp

The problem is indeed on the client side, but I cannot fixed it there because it is not possible in that piece of software. How can I use the urldecode function for the request url? I tried but it does not work.

christiaanvaken avatar Feb 18 '22 18:02 christiaanvaken

You can simply use it like this in your action:

$value = $request->getParameter('value');;

parse_str(urldecode($value), $data);

$http_rule = $data['value'];
$http_code = $data['status'];
$http_protocol = $data['protocol'];

chriskapp avatar Feb 18 '22 18:02 chriskapp

Hmm this does not work I'm afraid.

christiaanvaken avatar Feb 21 '22 08:02 christiaanvaken

Ok, so I think the problem regarding the parameters is not related to Fusio but to help you, you may want to take a look at the following script s.

<?php

$value = '31103%26status%3D402%26protocol%3DGET';

parse_str(urldecode($value), $data);

var_dump($data);

This results in:

array(3) {
  [31103]=>
  string(0) ""
  ["status"]=>
  string(3) "402"
  ["protocol"]=>
  string(3) "GET"
}

so if the $request->getParameter('value'); contains the value like described you could then get those value out of the string. But in general I would of course recommend to fix the request so that you can access the parameters normally via getParameter.

chriskapp avatar Feb 26 '22 23:02 chriskapp

It is weird that above does not work in the PHP Sandbox function.

christiaanvaken avatar Mar 04 '22 07:03 christiaanvaken