mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Fix caching of parsed URL queries broken
Ensure that changes to query objects dont make it into the cache
This commit is contained in:
parent
03e9fe6195
commit
623651d84b
@ -25,32 +25,40 @@ def debounce(func, wait, immediate=False):
|
|||||||
if call_now:
|
if call_now:
|
||||||
func.apply(context, args)
|
func.apply(context, args)
|
||||||
|
|
||||||
|
if Object.assign:
|
||||||
|
copy_hash = def (obj):
|
||||||
|
return Object.assign({}, obj)
|
||||||
|
else:
|
||||||
|
copy_hash = def (obj):
|
||||||
|
return {k:obj[k] for k in Object.keys(obj)}
|
||||||
|
|
||||||
|
|
||||||
def parse_url_params(url=None, allow_multiple=False):
|
def parse_url_params(url=None, allow_multiple=False):
|
||||||
cache = parse_url_params.cache
|
cache = parse_url_params.cache
|
||||||
url = url or window.location.href
|
url = url or window.location.href
|
||||||
if cache[url]:
|
if cache[url]:
|
||||||
return parse_url_params.cache[url]
|
return copy_hash(parse_url_params.cache[url])
|
||||||
qs = url.indexOf('#')
|
qs = url.indexOf('#')
|
||||||
ans = {}
|
ans = {}
|
||||||
if qs < 0:
|
if qs < 0:
|
||||||
cache[url] = ans
|
cache[url] = ans
|
||||||
return ans
|
return copy_hash(ans)
|
||||||
q = url.slice(qs + 1, (url.length + 1))
|
q = url.slice(qs + 1, (url.length + 1))
|
||||||
if not q:
|
if not q:
|
||||||
cache[url] = ans
|
cache[url] = ans
|
||||||
return ans
|
return copy_hash(ans)
|
||||||
pairs = q.replace(/\+/g, " ").split("&")
|
pairs = q.replace(/\+/g, " ").split("&")
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
key, val = pair.partition('=')[::2]
|
key, val = pair.partition('=')[::2]
|
||||||
key, val = decodeURIComponent(key), decodeURIComponent(val)
|
key, val = decodeURIComponent(key), decodeURIComponent(val)
|
||||||
if allow_multiple:
|
if allow_multiple:
|
||||||
if ans[key] is undefined:
|
if ans[key] is undefined:
|
||||||
ans[key] = []
|
ans[key] = v'[]'
|
||||||
ans[key].append(val)
|
ans[key].append(val)
|
||||||
else:
|
else:
|
||||||
ans[key] = val
|
ans[key] = val
|
||||||
cache[url] = ans
|
cache[url] = ans
|
||||||
return ans
|
return copy_hash(ans)
|
||||||
parse_url_params.cache = {}
|
parse_url_params.cache = {}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user