mirror of
https://github.com/koalyptus/TableFilter.git
synced 2026-03-18 08:29:50 +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
|
|
@ -36,14 +36,17 @@ test('Can update URL hash', function() {
|
|||
|
||||
// assert
|
||||
deepEqual(location.hash,
|
||||
'#{"page":2,"page_length":4,"col_2":{"flt":">500"}}',
|
||||
'#%7B%22page%22%3A2%2C%22page_length%22%3A4%2C%22'+
|
||||
'col_2%22%3A%7B%22flt%22%3A%22%3E500%22%7D%7D',
|
||||
'URL hash updated');
|
||||
});
|
||||
|
||||
test('Can parse a URL hash', function() {
|
||||
// setup
|
||||
var hashStr = '#{"page":2,"page_length":4,"col_2":{"flt":">500"}}';
|
||||
|
||||
// URL-encoded version of:
|
||||
// #{"page":2,"page_length":4,"col_2":{"flt":">500"}}
|
||||
var hashStr = '#%7B%22page%22%3A2%2C%22page_length%22%3A4'+
|
||||
'%2C%22col_2%22%3A%7B%22flt%22%3A%22%3E500%22%7D%7D'
|
||||
// act
|
||||
var result = hash.parse(hashStr);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue