Problem with accents and special characters when using the get method

0

I am working on an API Rest with Symfony 2.8. I have been given the following case: when they make a request to the URL /search , this usually comes:

http://{servidor.com}/search/libros?q=vacaciones&language=es

the request is handled in the controller in this way:

public function searchAction($elemento, ParamFetcherInterface $paramFetcher){
    $q = $paramFetcher->get('q');

    // ... demas proceso, haciendo consulta a bbdd

Recently I have found myself asking this request:

http://{servidor.com}/search/libros?q=democr%C3%A1tico&language=es

and when I do a var_dump ($ q) on the controller, I find that $ q is democratic .

This seems to be a problem of character conversion, utf8 or something similar.

Of course, I understand that the request is incorrect, but I have been asked to correct this problem in my application in the meantime. However, I can not find configuration or conversion form. In addition, although the request is worth democr%C3%A1tico , when it arrives at the controller it is already transformed with the characters á .

I guess you can change the configuration of the FosRestBundle but in the official documentation not nothing appears about utf8. Does this problem sound to someone? Can you help me?

    
asked by Jakala 11.04.2018 в 17:00
source

2 answers

0

what happens is that when you pass variables through the browser by the get method, it converts special characters (such as accent characters or characters like '# $%') into% code, (also known as URL code or URI code), what you can do is: 1. Try not to send strings that contain these characters. 2. Use a PHP function that converts the strings with URI code in the original strings, you can use urldecode() for this, for example, I leave you a link so you can see some examples, I hope you find it helpful, greetings.

    
answered by 11.04.2018 в 17:38
0

In the case that concerns me, the framework already uses the encoding of urldecode internally to obtain the Request object, which is what I use to obtain the parameters.

My problem here has been another, the configuration of the nginx server did not take into account the utf-8 encoding. I added it in the configuration line:

charset: UTF8;

And once the server has restarted, the application has responded correctly.

    
answered by 13.04.2018 в 10:17