Skip to content

Commit

Permalink
Fix getSelectorFromElement when # is a selector (#21615)
Browse files Browse the repository at this point in the history
* Fix getSelectorFromElement when # is a selector

* Thanks to @vanduynslagerp remove regex to validate selector
  • Loading branch information
Johann-S authored and mdo committed Mar 19, 2017
1 parent f2f8051 commit f2f2e39
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions js/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@ const Util = (($) => {

getSelectorFromElement(element) {
let selector = element.getAttribute('data-target')

if (!selector) {
if (!selector || selector === '#') {
selector = element.getAttribute('href') || ''
selector = /^#[a-z]/i.test(selector) ? selector : null
}

return selector
try {
const $selector = $(selector)
return $selector.length > 0 ? selector : null
} catch (error) {
return null
}
},

reflow(element) {
Expand Down

0 comments on commit f2f2e39

Please sign in to comment.