aboutsummaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorJohann-S <[email protected]>2017-11-07 12:41:06 +0100
committerGitHub <[email protected]>2017-11-07 12:41:06 +0100
commit79d6b574cc0946889eb2ef23c765bab50c2a6d60 (patch)
treef2fb33479a4278f781e3a22b05e32e7277b04546 /js/src
parent26dc17bcd23fd2f5fd762c5cb73c6a670bd5f897 (diff)
downloadbootstrap-79d6b574cc0946889eb2ef23c765bab50c2a6d60.tar.xz
bootstrap-79d6b574cc0946889eb2ef23c765bab50c2a6d60.zip
Escape ID in Util.getSelectorFromElement (#24700)
Diffstat (limited to 'js/src')
-rw-r--r--js/src/util.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/js/src/util.js b/js/src/util.js
index 71f93a7c5..ef2cc3c57 100644
--- a/js/src/util.js
+++ b/js/src/util.js
@@ -87,6 +87,14 @@ const Util = (($) => {
}
}
+ function escapeId(selector) {
+ // we escape IDs in case of special selectors (selector = '#myId:something')
+ // $.escapeSelector does not exist in jQuery < 3
+ selector = typeof $.escapeSelector === 'function' ? $.escapeSelector(selector).substr(1) :
+ selector.replace(/(:|\.|\[|\]|,|=|@)/g, '\\$1')
+
+ return selector
+ }
/**
* --------------------------------------------------------------------------
@@ -112,6 +120,11 @@ const Util = (($) => {
selector = element.getAttribute('href') || ''
}
+ // if it's an ID
+ if (selector.charAt(0) === '#') {
+ selector = escapeId(selector)
+ }
+
try {
const $selector = $(document).find(selector)
return $selector.length > 0 ? selector : null