Hash in a GET type service

Asked

Viewed 121 times

1

I have a service where I make a request of type GET that does a search in the groups of my application, the problem is that the user created a group called #nome-do-grupo, and when he goes to do the name search and he puts the hash, the error search because there is no way to send the hash to the server request.

I tried to use the encodeURIComponent but the search did not happen, I started to do a regex to remove the hashs from the string, but I would have to predict the maximum of other broken characters that it can put so it was sent.

If anyone has been through this, as you do in this case ?

  • When you use encodeURIComponent, the string is escaped as %23nome-do-grupo? Maybe it’s the case that Code is missing on the server side?

  • And then I used the encodeURIComponent and it wasn’t rolling because there was another script that was taking the term and giving another escape it then was getting %2523name-of-the-group, I took this escape and it worked as you described, then I had other problems with the other characters and I did it here encodeURIComponent(str).replace(/[!'()]/g, escape).replace(/\*/g, '') ai worked properly.

1 answer

1


After breaking a little head and having problems with other characters I did this function and worked correctly:

encodeURIComponent(str).replace(/[!'()]/g, escape).replace(/\*/g, '')  

The problem I had was that after the encodeURIComponent there was another script that gave a escape leaving the url parameter this way %2523 (in the case of hash in the search) so I took this escape, then I used the regex because the encodeURIComponent cannot 'find' these ~!*()' characters and at the end I replaced * for nothing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.