diff --git a/src/htmx.js b/src/htmx.js index 5dadbd3a..96bb2c20 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -692,9 +692,13 @@ return (function () { var TITLE_FINDER = /([\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]; + } } } diff --git a/test/core/ajax.js b/test/core/ajax.js index 942f2713..2f8f4aee 100644 --- a/test/core/ajax.js +++ b/test/core/ajax.js @@ -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" + "Clicked!"); + }); + var btn = make('') + 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, {}, "" + newTitle + "fooClicked!"); + }); + var btn = make('') + 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) {