mirror of
https://github.com/koalyptus/TableFilter.git
synced 2026-03-16 15:45:45 +01:00
URL Encode State Hash
You'll notice a mild asymmetry in how hash was
saved vs retrieved.
The retrieval was:
JSON.parse(decodeUrlComponent(hash))
The save was:
JSON.stringify(hash)
I modified it to:
JSON.stringify(encodeUrlComponent(hash))
The reason I noticed this is in one of my apps,
I wanted to be able to copy/share a stateful filter URL.
However without the url encoding, those auto-parsers
of URLs were missing the full filter.
TESTING CONDUCTED:
1. Updated the Hash unit tests to both parse the
encoded string, as well as generate it.
2. Ran "grunt", which has built/tested/jslinted
the code.
This commit is contained in:
parent
48ce8bf3db
commit
fb2f201f29
10 changed files with 22 additions and 18 deletions
|
|
@ -4,6 +4,7 @@ import {root} from '../root';
|
|||
const JSON = root.JSON;
|
||||
const location = root.location;
|
||||
const decodeURIComponent = root.decodeURIComponent;
|
||||
const encodeURIComponent = root.encodeURIComponent;
|
||||
|
||||
/**
|
||||
* Checks if browser has onhashchange event
|
||||
|
|
@ -75,7 +76,7 @@ export class Hash {
|
|||
* @param {State} state Instance of State
|
||||
*/
|
||||
update(state) {
|
||||
let hash = `#${JSON.stringify(state)}`;
|
||||
let hash = `#${encodeURIComponent(JSON.stringify(state))}`;
|
||||
if (this.lastHash === hash) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue