URL Encoding—Ampersand Problem

Vecta picture Vecta · Aug 10, 2011 · Viewed 79.9k times · Source

I'm having some trouble with some character encoding causing some problems with a search form on my website. One of the possible field values has an ampersand in it. When this is selected and a search is submitted the ampersand is encoded to: %2526

Upon using the pagination links at the bottom of the page and navigating to the second page in the list of results the ampersand is encoded to: %26

Finally...in an attempt to navigate to the 3rd page in the list the ampersand is changed back to: & This breaks the form as it assumes there's a variable that isn't actually there.

Why is the encoding changing? How can I fix this? Thanks for your help!

Answer

Andrew Lee picture Andrew Lee · Aug 10, 2011

It looks like the field is being encoded twice. First pass will result in & changed into %26, then urlencoding %26 will result in %2526, since the encoding for % itself is %25.