Skip to content

Commit

Permalink
Avoid using location.hash as jQuery selector directly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mislav committed Dec 3, 2014
1 parent 4d8f92e commit c3ca1c3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions jquery.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ function pjax(options) {
pjax.state.url = url.href
window.history.replaceState(pjax.state, container.title, url.href)

var target = $(url.hash)
if (target.length) $(window).scrollTop(target.offset().top)
var target = document.getElementById(url.hash.slice(1))
if (target) $(window).scrollTop($(target).offset().top)
}

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

0 comments on commit c3ca1c3

Please sign in to comment.