-
-
Notifications
You must be signed in to change notification settings - Fork 79k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly escape IDs in getSelector()
to handle weird IDs
#35566
Properly escape IDs in getSelector()
to handle weird IDs
#35566
Conversation
Nice job @pierresouchay . I 've done some testing it and seems it brings another 'feature', enabling use ids starting with number. Please add some tests to support your MR 😃 |
@GeoSot can you approve the worklow, so I can test it does not break anything? |
You can try |
@GeoSot Thanks, I'll try to add the test this evening. Do you have suggestion on what to test? I think I'll simply change a collapse test to target 0/my/id instead of test2 id... |
9bfd9ea
to
6cad761
Compare
@GeoSot all done, I applied linter, added test with problematic ID and rebased |
You probably need to add a test on |
@GeoSot Done in last commit |
@GeoSot Current support is not bad https://caniuse.com/mdn-api_css_escape Does it fit the currently supported browsers for Bootstrap? |
@GeoSot I could do another minor change (if you want me to): if (selector !== null && selector.startsWith('#')) {
// document.querySelector needs escaping to handle IDs (html5+) containing for instance /
selector = '#' + CSS.escape(selector.slice(1))
} to be changed to: if (selector !== null && selector.startsWith('#') && window.CSS && window.CSS.escape) {
// document.querySelector needs escaping to handle IDs (html5+) containing for instance /
selector = '#' + CSS.escape(selector.slice(1))
} => so It would work as it does now for very old browsers not supporting CSS.escape (so, would still break on non HTML4 IDs, but would work for HTML4 IDs) |
Hello @XhmikosR, I added the tests (as seen in the labels of the PR), do you need more? (BTW: I need someone to approve the tests in order to run) |
Discussing this with @XhmikosR , there are about 7 usages of Indeed, your proposal is valid, but it doesn't cover all possibilities. I can see two possible solutions here.
Have in mind that there might be cases like |
IMHO, this change fixes bugs, not all of them, ans is straightforward (while we might argue on my comment about detecting the CSS.escape() function) |
Personally, I am ok with this check @XhmikosR , please tell us you opinion. shall we go with the MVP or not? |
I 'll approve it as it solves the 3 issues, keeping in mind that it is not an end up solution (the other 7 occurrences have to be changed in the future) |
a79e2d1
to
e66a9fe
Compare
… to run on older browsers
Co-authored-by: GeoSot <[email protected]>
46dc62e
to
cb86a0e
Compare
cb86a0e
to
332cd26
Compare
Co-authored-by: Julien Déramond <[email protected]>
@GeoSot Thank you, we are close \o/ |
No, even more than close. We are done ;) Thank you a lot for your patience and your time |
getSelector()
to handle weird IDs
I still see error like this with 5.2.3:
|
@pierresouchay you should make a separate issue with all the info there. |
@XhmikosR adding this to a test illustrates the bug: diff --git a/js/tests/unit/scrollspy.spec.js b/js/tests/unit/scrollspy.spec.js
index c7951e6..704b52a 100644
--- a/js/tests/unit/scrollspy.spec.js
+++ b/js/tests/unit/scrollspy.spec.js
@@ -341,11 +341,13 @@ describe('ScrollSpy', () => {
' <ul class="nav">',
' <li class="nav-item"><a class="nav-link" id="a-1" href="#div-1">div 1</a></li>',
' <li class="nav-item"><a class="nav-link" id="a-2" href="#div-2">div 2</a></li>',
+ ' <li class="nav-item"><a class="nav-link" id="a-2.1" href="#div-2.1">div 2</a></li>',
' </ul>',
'</nav>',
'<div class="content" style="overflow: auto; height: 50px">',
' <div id="div-1" style="height: 100px; padding: 0; margin: 0">div 1</div>',
' <div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>',
+ ' <div id="div-2.1" style="height: 200px; padding: 0; margin: 0">div 2.1</div>',
'</div>'
].join('') Error:
|
@larseggert Could you please create a separate issue with this information and the problem you have? Otherwise, it is very difficult for us to track since this PR is already merged. |
See #37858 |
IDs need to be escaped before document.querySelector() is called
Will fix #35565
Closes #34412
closes #36939
Fixes #34381
Fixes #31099