Search code examples
javascriptangularjsnode.jsencodeurlencode

EncodeURIComponent/DecodeURIComponent with characters like "é"


I have a web application, with some drop-down list. One of these list have some parameters with an accent, such as : "Bonjour/COUCOU SPéCIALISTE/AB12345"

So when I select it and I made the research I end up with the following url:

abcdefgh.com/someFunction?way=null&motive=bonjour%2Fcoucou+spécialiste%2FAB12345

In my function, I have:

var somethingPercentage = getSomethingPercentage(
    decodeURIComponent(queryParams.way),
    decodeURIComponent(queryParams.motive)
);

And, in a config file, I have made the matching parameter like this:

"bonjour/coucou+spécialiste/ab12345": 0.01

In the result, I have a bad call. But when I select some parameters with no accent, I don't have this problem and the result is the good.

The problem is the same if the parameter have some space.

Why is this behaviour happening?


Solution

  • I have just found.

    I have just put

    logger.info(decodeURIComponent(queryParams.motive));
    

    after the following code :

    var somethingPercentage = getSomethingPercentage(
    decodeURIComponent(queryParams.way),
    decodeURIComponent(queryParams.motive));
    

    Now, i have find the necessary value to match.

    It was not a problem of "é" but a problem of space in my case.