Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding / Decoding issue #848

Closed
NicoD opened this issue Feb 16, 2016 · 5 comments
Closed

Encoding / Decoding issue #848

NicoD opened this issue Feb 16, 2016 · 5 comments
Milestone

Comments

@NicoD
Copy link

NicoD commented Feb 16, 2016

The bracket characters (unsafe) and equal character (reserved) are directly set in the url query string or fragment without encoding.

example:
https://demo.algolia.com/instant-search-demo/?q=&hPP=10&idx=instant_search&p=0&nR[price][>=][0]=2676&is_v=1
should be:
https://demo.algolia.com/instant-search-demo/?q=&hPP=10&idx=instant_search&p=0&nR%5Bprice%5D%5B%3E%3D%5D%5B0%5D=2676&is_v=1

(same thing observed with useHash = true)

@vvo
Copy link
Contributor

vvo commented Feb 16, 2016

Hi @NicoD this should be handled by the browsers in a natural way: the url looks good and can be copy pasted in a url bar, did you observe any bad behavior?

@NicoD
Copy link
Author

NicoD commented Feb 16, 2016

Hi @vvo ,

here some examples with a failure:

  • here in github, in my previous comment. When I copied the first url (which is the instantsearch url), github had itself encoded the unsafe characters (brackets) but not the =. The link does not work when following it. (however the second link - which i encoded manually - works fine)
  • i had the same issue when reading an instantsearch url through a slack client (not the web client)

=> i suppose this error may happened on others clients that encode the query string: the brackets are normaly url urlencoded, but not the = which is considered as a separator.

  • js url parsing lib (like urljs and browserify url) fail parsing the query string or fragment because of the = and the non encoded chars.

I think it would be safer to urlencode all the reserved and unsafe chars in the query string and the fragment (https://tools.ietf.org/html/rfc3986)

@vvo vvo added the Type: Bug label Feb 24, 2016
@vvo vvo added this to the 1.3 milestone Feb 24, 2016
@vvo
Copy link
Contributor

vvo commented Mar 2, 2016

@NicoD As for copy pasting the url from the urlbar or right click a link and copy from the context menu then paste it anywhere => it's the responsibility of the client to do things well. Github does, slack also it seems

On this issue, I was able to fix it by decoding the uri every time its needed (loading the page, back button): decodeURIComponent.

Seems to work well, let me know. The fix is incoming

@vvo
Copy link
Contributor

vvo commented Mar 3, 2016

This is not as easy as I thought, decoding when receiving has his owns quirks: values (facet refinements) with & or = are decoded and then mis interpreted as separators.

@vvo
Copy link
Contributor

vvo commented Mar 3, 2016

To completely solve this issue we will have to stop trying to be smart in the helper: trying to only encode values and not param delimiters.

We should just use encode: true from qs/ module because what we did was worse: encoding values while not encoding param separators like []. It turns out that this is not well supported in cases where you copy paste the url.

I am sorry I am the one that thought this would be feasible but it's not. We must encode everything and thus have not so good looking uris.

cc @bobylito would you be ok removing our custom encoding code from the helper and just use encode: true from qs?

@vvo vvo closed this as completed in bea38e3 Mar 4, 2016
vvo pushed a commit that referenced this issue Mar 4, 2016
<a name="1.3.0"></a>
# [1.3.0](v1.2.5...v1.3.0) (2016-03-04)

### Bug Fixes

* **browser support:** make IE lte 10 work by fixing Object.getPrototypeOf ([bbb264b](bbb264b))
* **menu,refinementList:** sort by count AND name to avoid reorders on refine ([02fe7bf](02fe7bf)), closes [#65](#65)
* **priceRanges:** pass the bound refine to the form ([ce2b956](ce2b956))
* **searchBox:** handle external updates of the query ([6a0af14](6a0af14)), closes [#803](#803)
* **searchBox:** stop setting the query twice ([91270b2](91270b2))
* **searchBox:** stop updating query at eachkeystroke with searchOnEnterKeyPressOnly ([28dc4d2](28dc4d2)), closes [#875](#875)
* **Slider:** do not render Slider when range.min === range.max ([f20274e](f20274e))
* **Template:** now render() when templateKey changes ([8906224](8906224))
* **toggle:** pass isRefined to toggleRefinement ([8ac494e](8ac494e))
* **url-sync:** always decode incoming query string ([bea38e3](bea38e3)), closes [#848](#848)
* **url-sync:** handle <base> href pages ([e58aadc](e58aadc)), closes [#790](#790)

### Features

* **collapsable widgets:** add collapsable and collapsed option ([c4df7c5](c4df7c5))
* **instantsearch:** allow overriding the helper.search function ([9a930e7](9a930e7))
* **rangeSlider:** allow passing min and max values ([409295c](409295c)), closes [#858](#858)
* **searchBox:** allow to pass a queryHook ([5786a64](5786a64))
* **Template:** allow template functions to return a React element ([748077d](748077d))
* **Template:** allow template functions to return a React element ([0f9296d](0f9296d))

### Performance Improvements

* **autoHideContainer:** stop re-creating React components ([8c89862](8c89862))
* **formatting numbers:** stop using a default locale, use the system one ([b056554](b056554))
* **nouislider:** upgrade nouislider, shaves some more ms ([fefbe65](fefbe65))
* **React:** use babel `optimisation` option for React ([95f940c](95f940c))
* **React, widgets:** implement shouldComponentUpdate, reduce bind ([5efaac1](5efaac1))
@vvo vvo reopened this Apr 15, 2016
@vvo vvo closed this as completed Apr 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants