Skip to content

Commit

Permalink
Merge pull request #8216 from elastic/jasper/backport/8212/5.x
Browse files Browse the repository at this point in the history
[backport] PR #8212 to 5.x - do not overencode unhashed states
  • Loading branch information
epixa authored Sep 10, 2016
2 parents b717844 + c257bbb commit f4f0dda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"dragula": "3.7.0",
"elasticsearch": "12.0.0-rc5",
"elasticsearch-browser": "12.0.0-rc5",
"encode-uri-query": "1.0.0",
"even-better": "7.0.2",
"expiry-js": "0.1.7",
"exports-loader": "0.6.2",
Expand Down
15 changes: 14 additions & 1 deletion src/ui/public/state_management/state_hashing/unhash_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import {
format as formatUrl,
} from 'url';

import encodeUriQuery from 'encode-uri-query';

import {
stringify as stringifyQueryString
} from 'querystring';

import unhashQueryString from './unhash_query_string';

export default function unhashUrl(urlWithHashes, states) {
Expand All @@ -26,11 +32,18 @@ export default function unhashUrl(urlWithHashes, states) {
if (!appUrlParsed.query) return urlWithHashes;

const appQueryWithoutHashes = unhashQueryString(appUrlParsed.query || {}, states);

// encodeUriQuery implements the less-aggressive encoding done naturally by
// the browser. We use it to generate the same urls the browser would
const appQueryStringWithoutHashes = stringifyQueryString(appQueryWithoutHashes, null, null, {
encodeURIComponent: encodeUriQuery
});

return formatUrl({
...urlWithHashesParsed,
hash: formatUrl({
pathname: appUrlParsed.pathname,
query: appQueryWithoutHashes,
search: appQueryStringWithoutHashes,
})
});
}

0 comments on commit f4f0dda

Please sign in to comment.