diff options
author | Johann-S <johann.servoire@gmail.com> | 2018-01-21 23:02:16 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2018-01-21 23:02:16 +0300 |
commit | 5a6be71791a0cc7199c20d2ac1f248612b805518 (patch) | |
tree | a582a9b0745b0e5c79d311ac0dff98a00adfb08d /js | |
parent | db70164d139c2cc331c671bec24547bd19bee8ac (diff) |
Remove escaping selector and add a warning to inform folks to escape their selectors (#25390)
Diffstat (limited to 'js')
-rw-r--r-- | js/src/util.js | 14 | ||||
-rw-r--r-- | js/tests/unit/util.js | 14 |
2 files changed, 1 insertions, 27 deletions
diff --git a/js/src/util.js b/js/src/util.js index 6e32e955d0..7e5d5de5c6 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -72,15 +72,6 @@ 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 - } - /** * -------------------------------------------------------------------------- * Public Util Api @@ -105,11 +96,6 @@ 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 diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js index e56bef18eb..83eb601a51 100644 --- a/js/tests/unit/util.js +++ b/js/tests/unit/util.js @@ -4,7 +4,7 @@ $(function () { QUnit.module('util') QUnit.test('Util.getSelectorFromElement should return the correct element', function (assert) { - assert.expect(5) + assert.expect(2) var $el = $('<div data-target="body"></div>').appendTo($('#qunit-fixture')) assert.strictEqual(Util.getSelectorFromElement($el[0]), 'body') @@ -12,18 +12,6 @@ $(function () { // Not found element var $el2 = $('<div data-target="#fakeDiv"></div>').appendTo($('#qunit-fixture')) assert.strictEqual(Util.getSelectorFromElement($el2[0]), null) - - // Should escape ID and find the correct element - var $el3 = $('<div data-target="#collapse:Example"></div>').appendTo($('#qunit-fixture')) - $('<div id="collapse:Example"></div>').appendTo($('#qunit-fixture')) - assert.strictEqual(Util.getSelectorFromElement($el3[0]), '#collapse\\:Example') - - // If $.escapeSelector doesn't exist in older jQuery versions (< 3) - var tmpEscapeSelector = $.escapeSelector - delete $.escapeSelector - assert.ok(typeof $.escapeSelector === 'undefined', '$.escapeSelector undefined') - assert.strictEqual(Util.getSelectorFromElement($el3[0]), '#collapse\\:Example') - $.escapeSelector = tmpEscapeSelector }) QUnit.test('Util.typeCheckConfig should thrown an error when a bad config is passed', function (assert) { |