1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

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
This commit is contained in:
Robert Knight 2015-12-02 20:09:09 +00:00
parent 04104f04d3
commit 34721a6742
2 changed files with 27 additions and 9 deletions

View File

@ -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 <a> 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 href="foobar.html" id="link">A link</a>',
testScript: function () {
};
});
it('should rewrite links in dynamically injected <a> 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);
});
});

View File

@ -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;
};
}