Skip to content

Commit

Permalink
title tags must come before any svg tags to update the title
Browse files Browse the repository at this point in the history
  • Loading branch information
strangeRabbit777 authored and carson committed May 17, 2021
1 parent 68bac7e commit c85789e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,13 @@ return (function () {

var TITLE_FINDER = /<title>([\s\S]+?)<\/title>/im;
function findTitle(content) {
var result = TITLE_FINDER.exec(content);
if (result) {
return result[1];
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];
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions test/core/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c85789e

Please sign in to comment.