escape colons in querySelector (#1314)

thank you!
This commit is contained in:
Nicolas Appriou 2023-04-02 01:36:15 +02:00 committed by GitHub
parent 32edfba6f2
commit 1e1b7cf94a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -803,7 +803,8 @@ return (function () {
forEach(fragment.querySelectorAll("[id]"), function (newNode) {
if (newNode.id && newNode.id.length > 0) {
var normalizedId = newNode.id.replace("'", "\\'");
var oldNode = parentNode.querySelector(newNode.tagName + "[id='" + normalizedId + "']");
var normalizedTag = newNode.tagName.replace(':', '\\:');
var oldNode = parentNode.querySelector(normalizedTag + "[id='" + normalizedId + "']");
if (oldNode && oldNode !== parentNode) {
var newAttributes = newNode.cloneNode();
cloneAttributes(newNode, oldNode);

View File

@ -979,4 +979,14 @@ describe("Core htmx AJAX Tests", function(){
}
});
it('should load tags with colon in their names', function() {
this.server.respondWith('GET', '/test', '<with:colon id="foobar">Foobar</with:colon>');
var btn = make('<button hx-get="/test">Give me colons!</button>');
btn.click();
this.server.respond();
btn.innerHTML.should.equal('<with:colon id="foobar">Foobar</with:colon>');
});
})