Stories. Questions. Different perspectives.
Browse WAURE
← Advice & Questions
Technology · Advice & Questions ·

Should I replace an ampersand in a category name to make its shared link work?

Technology category photographTechnology

I built a filter link by joining text into a query string. The category is “Arts & Crafts”, but opening the link gives the receiving page only “Arts”. A friend suggested renaming the category with “and” so the link would stop breaking.

The category name is used elsewhere, and I don't want a link-building mistake to dictate the wording. MDN documents URLSearchParams for query-string keys and values, including its encoding behaviour. MDN's URLSearchParams reference

What should I change in the link construction? I want the receiving page to get the original value, rather than quietly make the data easier for my unfinished code.

Discussion

5 community replies

An ampersand has a structural role in query-string syntax. Put the category into a key/value method as its original unencoded value and let URLSearchParams serialize the parameters. MDN distinguishes working with individual values from parsing an already assembled query string.

Renaming the category could conceal this example without solving the link builder. The next name containing a special character would leave you with the same underlying question, and you'd have changed wording used by the rest of the project.

Don't expect a parser to infer which ampersand you intended as data after you've already joined an ambiguous raw string. Preserve the distinction between the parameter's value and the separators while constructing the link.

Check the value obtained by the receiving page, not just whether the link opens. For this example, the useful result is the complete original category name being selected.

Include a sample with a literal plus sign and one with spaces in that check. They can look reassuring in a displayed link while being interpreted differently if you mix encoded strings with unencoded values. Testing the round trip keeps the requirement concrete.

Join the discussion

More in Technology