Search code examples
phprouteslumen

Lumen (5.8.7) - final parameter in route includes trailing slash


I am using lumen 5 as a simple api to deliver data to another web application. The final parameter in the request is encrypted. This has been working nicely now for months, but today we had trouble where the final, encrypted parameted ended in a slash:

https://xxx.yyy.zz/test/69UBiV8iBSDBQMumdaU/

where the trailing slash in fact is part of the the encrypted string...

In my routes/web.php:

...
router->get('/test/{code:.*}', 'SoapController@show');
...

For testing purposes, I also commented out these lines in public/.htaccess:

# Redirect Trailing Slashes If Not A Folder...
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} /(.*)/$
#RewriteRule ^ /%1 [R=301,L]

I can confirm that the url keeps the trailing slash, but I still get an error:

at Application->Laravel\Lumen\Concerns\{closure}(8, 'Trying to get property of non-object', 
 '/var/www/html/test/app/Http/Controllers/SoapController.php', 133, array('testparam' => 
 '**69UBiV8iBSDBQMumdaU**', 'response' => object(stdClass), 'xml' => '<package><diffgram 
 xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml- 
 diffgram-v1"/></package>', 'customer' => object(SimpleXMLElement)))

which tells me that the parameter is received without the trailing slash, and does not get decrypted properly.

My question is: How do I keep the trailing slash as part of the parameter string so that it can be decrypted correctly?

Thank you


Solution

  • The / is part of an URL. So you must switch to a URL safe encryption or encoding method. This means removing the +, / and = from the encryption in the URL. I think you can use urlencode and urldecode for this (maybe in combination with base64_encode and base64_decode.

    You also can use $request->url(); and parse it yourself by splitting on / using preg_split("/\//", $string, -1, PREG_SPLIT_DELIM_CAPTURE);. Notice this will only work if the / is on the end. I don't know what encryption you are using.