Skip to content

Commit

Permalink
Handle '+' as space in URI (hound-search#313)
Browse files Browse the repository at this point in the history
Traditional URI encoding uses '+' instead of '%20' to represent
spaces in URI parameters, but the decodeURIComponent method
does not recognize this representation.

This is significant because Chrome's "Manage Search Engines"
settings page, which lets users add arbitrary search engines
as shortcuts in that browser's location bar, represents spaces
using the '+' character. So, if you try to add a local Hound
instance to your Chrome search engines, any multi-word search
will be replaced by a weird regular expression, as the '+'
characters will be retained in the search box.

For instance, without this change, if you were to set 'hound'
as the shortcut term, then entering 'hound some thing' will
send the search parameter '?q=some+thing' to Hound, resulting
in a search for the regular expression /some+thing/, matching
'something', 'someething', 'someeeeeeeeething', etc.

Regular expression search is not affected by this change,
because an actual "+" character entered using this Chrome
feature will be encoded as %2B, and the '+' will appear in
Hound's search box correctly.
  • Loading branch information
jacobrose authored and kellegous committed Jun 16, 2019
1 parent e3b1b43 commit c75143d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
4 changes: 4 additions & 0 deletions ui/assets/js/hound.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ var ParamsFromQueryString = function(qs, params) {
return;
}

// Handle classic '+' representation of spaces, such as is used
// when Hound is set up in Chrome's Search Engine Manager settings
pair[1] = pair[1].replace('+', ' ');

params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
});

Expand Down
Loading

0 comments on commit c75143d

Please sign in to comment.