(Please no lectures on how this is not the right way to construct URLs etc; this is legacy code and I have bigger fish to fry. I just want to know what the browser thinks it's doing.)
Given the following function:
function redirectToSearch(baseURL) {
var searchString = document.getElementById("searchBox").value;
document.location = baseURL + "&searchString=" + searchString;
}
where the searchBox
element is a text field: if you put in something like
{ a ^ b } " c | d "
in the text field and call this function, the resulting URL, as redirected-to, ends in
searchString={%20a%20^%20b%20}%20%22c%20|%20d%22
-- spaces and quotation marks are escaped, but nothing else, even though {
, }
, and |
should also be invalid characters. This seems to be true in Chrome, Firefox, and IE.
Okay, presumably I can fix this by encoding the string myself, but what I want to know is, why just spaces and quotes (and possibly other characters I haven't discovered)? Why not either all invalid characters, or none?