From 34721a674209d2ef25b0e4981dc17549ec409511 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Wed, 2 Dec 2015 20:09:09 +0000 Subject: [PATCH] Override HTMLAnchorElement.prototype.toString() The values returned by getting the 'href' and 'toString' properties of an anchor element should be the same. This inconsistency broke the URL polyfill in https://github.com/inexorabletash/polyfill under Microsoft Edge --- karma-tests/wombat.spec.js | 33 ++++++++++++++++++++++++--------- pywb/static/wombat.js | 3 +++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/karma-tests/wombat.spec.js b/karma-tests/wombat.spec.js index fbb9b33d..56e6af7e 100644 --- a/karma-tests/wombat.spec.js +++ b/karma-tests/wombat.spec.js @@ -34,7 +34,6 @@ function runWombatTest(testCase, done) { window.assert = { equal: function (a, b) { if (a !== b) { - x.equal(a, b); console.error('Mismatch between', a, 'and', b); throw new Error('AssertionError'); } @@ -133,8 +132,9 @@ describe('WombatJS', function () { }); describe('anchor rewriting', function () { - it('should rewrite links in dynamically injected tags', function (done) { - runWombatTest({ + var config; + beforeEach(function () { + config = { initScript: function () { wbinfo = { wombat_opts: {}, @@ -144,13 +144,28 @@ describe('WombatJS', function () { }, wombatScript: wombatScript, html: 'A link', - testScript: function () { + }; + }); + + it('should rewrite links in dynamically injected tags', function (done) { + config.testScript = function () { + if (domTests.areDOMPropertiesConfigurable()) { var link = document.getElementById('link'); - if (domTests.areDOMPropertiesConfigurable()) { - assert.equal(link.href, 'http:///base/karma-tests/foobar.html'); - } - }, - }, done); + assert.equal(link.href, 'http:///base/karma-tests/foobar.html'); + } + }; + + runWombatTest(config, done); + }); + + it('toString() should return the rewritten URL', function (done) { + config.testScript = function () { + if (domTests.areDOMPropertiesConfigurable()) { + var link = document.getElementById('link'); + assert.equal(link.href, link.toString()); + } + }; + runWombatTest(config, done); }); }); diff --git a/pywb/static/wombat.js b/pywb/static/wombat.js index e089cbdc..8c0956cd 100644 --- a/pywb/static/wombat.js +++ b/pywb/static/wombat.js @@ -1397,6 +1397,9 @@ var wombat_internal = function($wbwindow) { } init_loc_override($wbwindow.HTMLAnchorElement.prototype, anchor_setter, anchor_getter); + $wbwindow.HTMLAnchorElement.prototype.toString = function () { + return this.href; + }; }