title tags must come before any svg tags to update the title

fixes https://github.com/bigskysoftware/htmx/issues/459
This commit is contained in:
carson 2021-05-17 11:39:22 -06:00
parent 78b2bddab0
commit bdefbd4fec
2 changed files with 34 additions and 3 deletions

View File

@ -692,11 +692,15 @@ return (function () {
var TITLE_FINDER = /<title>([\s\S]+?)<\/title>/im;
function findTitle(content) {
if(content.indexOf('<title>') > -1 &&
(content.indexOf('<svg>') == -1 ||
content.indexOf('<title>') < content.indexOf('<svg>'))) {
var result = TITLE_FINDER.exec(content);
if (result) {
return result[1];
}
}
}
function selectAndSwap(swapStyle, target, elt, responseText, settleInfo) {
var title = findTitle(responseText);

View File

@ -789,6 +789,33 @@ describe("Core htmx AJAX Tests", function(){
window.document.title.should.equal("htmx rocks!");
});
it('svg title tags do not update title', function()
{
var originalTitle = window.document.title
this.server.respondWith("GET", "/test", function (xhr) {
xhr.respond(200, {}, "<svg><title>" + originalTitle + "UPDATE" + "</title></svg>Clicked!");
});
var btn = make('<button hx-get="/test">Click Me!</button>')
btn.click();
this.server.respond();
btn.innerText.should.equal("Clicked!");
window.document.title.should.equal(originalTitle);
});
it('title tags before svg title tags do update title', function()
{
var originalTitle = window.document.title
var newTitle = originalTitle + "!!!";
this.server.respondWith("GET", "/test", function (xhr) {
xhr.respond(200, {}, "<title>" + newTitle + "</title><svg><title>foo</title></svg>Clicked!");
});
var btn = make('<button hx-get="/test">Click Me!</button>')
btn.click();
this.server.respond();
btn.innerText.should.equal("Clicked!");
window.document.title.should.equal(newTitle);
});
it('title update does not URL escapte', function()
{
this.server.respondWith("GET", "/test", function (xhr) {