Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL query string has a comma in the string

I am having an issue with a URL query string and I believe the issue is that my parameter sometimes has a comma in it.

What happens is I have a query string that is generated from a list of group names so that my string looks something like:

 Group=GroupName1,GroupName2,GroupName3

While doing some testing I noticed that some of my groups are not being displayed on the page even though they are in the query string. Then I noticed that the groups that are not showing are those that have a comma in the name. For example:

 Group=People,%20Places%20and%20Stuff

Obviously the query string gets parsed looking for 'People' as a group and 'Places and Stuff' as a group. This is an issue because the group is 'People, Places and Stuff'. I don't have any control over the group names so they cannot be changed to not include commas. I tried to encode the comma in the string using %2C however that had no impact.

I did some searching but I couldn't find anything other than a suggestion about changing the server so that the delimiter isn't a comma but I don't have the ability to that. Any other solution or am I stuck?

like image 906
AxGryndr Avatar asked Mar 03 '17 15:03

AxGryndr


People also ask

Can URL path contain comma?

Commas are allowed in the filename part of a URL, but are reserved characters in the domain*, as far as I know.

How can I tell if a URL has a query string?

To check if a url has query parameters, call the includes() method on the string, passing it a question mark as a parameter, e.g. str. includes('? ') . If the url contains query parameters, the includes method will return true , otherwise false is returned.

What is URL query string?

A query string is the portion of a URL where data is passed to a web application and/or back-end database. The reason we need query strings is that the HTTP protocol is stateless by design. For a website to be anything more than a brochure, you need to maintain state (store data).


1 Answers

After doing a bunch of hunting I finally found the answer.

I was on the right track encoding the comma as %2C however this has to be preceded by an escape character of %5C. Therefore the url query string would be the following:

 Group=People%5C%2C%20Places%20and%20Stuff
like image 167
AxGryndr Avatar answered Sep 20 '22 18:09

AxGryndr