mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-30 21:41:57 -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:
|
||||
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):
|
||||
cache = parse_url_params.cache
|
||||
url = url or window.location.href
|
||||
if cache[url]:
|
||||
return parse_url_params.cache[url]
|
||||
return copy_hash(parse_url_params.cache[url])
|
||||
qs = url.indexOf('#')
|
||||
ans = {}
|
||||
if qs < 0:
|
||||
cache[url] = ans
|
||||
return ans
|
||||
return copy_hash(ans)
|
||||
q = url.slice(qs + 1, (url.length + 1))
|
||||
if not q:
|
||||
cache[url] = ans
|
||||
return ans
|
||||
return copy_hash(ans)
|
||||
pairs = q.replace(/\+/g, " ").split("&")
|
||||
for pair in pairs:
|
||||
key, val = pair.partition('=')[::2]
|
||||
key, val = decodeURIComponent(key), decodeURIComponent(val)
|
||||
if allow_multiple:
|
||||
if ans[key] is undefined:
|
||||
ans[key] = []
|
||||
ans[key] = v'[]'
|
||||
ans[key].append(val)
|
||||
else:
|
||||
ans[key] = val
|
||||
cache[url] = ans
|
||||
return ans
|
||||
return copy_hash(ans)
|
||||
parse_url_params.cache = {}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user