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

Avoid changing the writability of the 'href' attr of <base>

Wombat overrides document.baseURI and <base>.href in order
to return the original URL rather than the proxied URL.

The <base>.href override however ended up making a writable
attribute read-only, which could trigger script errors
in strict-mode JS.

Fix this by avoiding replacing the setter for a DOM property
if no replacement setter is provided.

Fixes an error loading Hypothesis under Microsoft Edge.
This commit is contained in:
Robert Knight 2015-11-26 13:54:47 +00:00
parent 70a098cbd4
commit 1484b06da6
2 changed files with 69 additions and 43 deletions

View File

@ -121,45 +121,66 @@ describe('WombatJS', function () {
}, done);
});
it('should rewrite document.baseURI', function (done) {
runWombatTest({
initScript: function () {
wbinfo = {
wombat_opts: {},
prefix: window.location.origin,
wombat_ts: '',
};
},
wombatScript: wombatScript,
testScript: function () {
var baseURI = document.baseURI;
if (typeof baseURI !== 'string') {
throw new Error('baseURI is not a string');
}
if (domTests.areDOMPropertiesConfigurable()) {
assert.equal(baseURI, 'http:///dummy.html');
}
},
}, done);
describe('anchor rewriting', function () {
it('should rewrite links in dynamically injected <a> tags', function (done) {
runWombatTest({
initScript: function () {
wbinfo = {
wombat_opts: {},
prefix: window.location.origin,
wombat_ts: '',
};
},
wombatScript: wombatScript,
html: '<a href="foobar.html" id="link">A link</a>',
testScript: function () {
var link = document.getElementById('link');
if (domTests.areDOMPropertiesConfigurable()) {
assert.equal(link.href, 'http:///foobar.html');
}
},
}, done);
});
});
it('should rewrite links in dynamically injected <a> tags', function (done) {
runWombatTest({
initScript: function () {
wbinfo = {
wombat_opts: {},
prefix: window.location.origin,
wombat_ts: '',
};
},
wombatScript: wombatScript,
html: '<a href="foobar.html" id="link">A link</a>',
testScript: function () {
var link = document.getElementById('link');
if (domTests.areDOMPropertiesConfigurable()) {
assert.equal(link.href, 'http:///foobar.html');
}
},
}, done);
describe('base URL overrides', function () {
it('document.baseURI should return the original URL', function (done) {
runWombatTest({
initScript: function () {
wbinfo = {
wombat_opts: {},
prefix: window.location.origin,
wombat_ts: '',
};
},
wombatScript: wombatScript,
testScript: function () {
var baseURI = document.baseURI;
if (typeof baseURI !== 'string') {
throw new Error('baseURI is not a string');
}
if (domTests.areDOMPropertiesConfigurable()) {
assert.equal(baseURI, 'http:///dummy.html');
}
},
}, done);
});
it('should allow base.href to be assigned', function (done) {
runWombatTest({
initScript: function () {
wbinfo = {
wombat_opts: {},
};
},
wombatScript: wombatScript,
testScript: function () {
'use strict';
var baseElement = document.createElement('base');
baseElement.href = 'http://foobar.com/base';
assert.equal(baseElement.href, 'http://foobar.com/base');
},
}, done);
});
});
});

View File

@ -379,11 +379,16 @@ var wombat_internal = function($wbwindow) {
}
try {
Object.defineProperty(obj, prop, {
configurable: false,
set: set_func,
get: get_func
});
var descriptor = {
configurable: true,
get: get_func,
};
if (set_func) {
descriptor.set = set_func;
}
Object.defineProperty(obj, prop, descriptor);
return true;
} catch (e) {