Skip to content

Commit c3ca1c3

Browse files
committed
Avoid using location.hash as jQuery selector directly
The URI fragment might have all sorts of data in it and will not always be a valid CSS query. The previous approach could have led to Sizzle syntax errors. Since we're only allowing lookups by ID, use `getElementById` here which will never error out, even for malformed values.
1 parent 4d8f92e commit c3ca1c3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

jquery.pjax.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ function pjax(options) {
327327
pjax.state.url = url.href
328328
window.history.replaceState(pjax.state, container.title, url.href)
329329

330-
var target = $(url.hash)
331-
if (target.length) $(window).scrollTop(target.offset().top)
330+
var target = document.getElementById(url.hash.slice(1))
331+
if (target) $(window).scrollTop($(target).offset().top)
332332
}
333333

334334
fire('pjax:success', [data, status, xhr, options])

0 commit comments

Comments
 (0)