18

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?

AxGryndr
  • 2,274
  • 2
  • 22
  • 45

1 Answers1

21

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
AxGryndr
  • 2,274
  • 2
  • 22
  • 45
  • 1
    For me, 2C% works OK, %5C%2C% does not work. Windows 10, git bash, curl. – Serhii Kushchenko Nov 06 '21 at 11:33
  • Don't forget to "decodeURIComponent" that query string https://stackoverflow.com/questions/747641/what-is-the-difference-between-decodeuricomponent-and-decodeuri – Daniel Dec 14 '21 at 19:50
  • That is a good point if you are trying to parse the URI component within your code. Fortunately, I was passing the query parameter to an existing application that handled this for me. – AxGryndr Dec 15 '21 at 21:36