mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +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:
parent
70a098cbd4
commit
1484b06da6
@ -121,45 +121,66 @@ describe('WombatJS', function () {
|
|||||||
}, done);
|
}, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should rewrite document.baseURI', function (done) {
|
describe('anchor rewriting', function () {
|
||||||
runWombatTest({
|
it('should rewrite links in dynamically injected <a> tags', function (done) {
|
||||||
initScript: function () {
|
runWombatTest({
|
||||||
wbinfo = {
|
initScript: function () {
|
||||||
wombat_opts: {},
|
wbinfo = {
|
||||||
prefix: window.location.origin,
|
wombat_opts: {},
|
||||||
wombat_ts: '',
|
prefix: window.location.origin,
|
||||||
};
|
wombat_ts: '',
|
||||||
},
|
};
|
||||||
wombatScript: wombatScript,
|
},
|
||||||
testScript: function () {
|
wombatScript: wombatScript,
|
||||||
var baseURI = document.baseURI;
|
html: '<a href="foobar.html" id="link">A link</a>',
|
||||||
if (typeof baseURI !== 'string') {
|
testScript: function () {
|
||||||
throw new Error('baseURI is not a string');
|
var link = document.getElementById('link');
|
||||||
}
|
if (domTests.areDOMPropertiesConfigurable()) {
|
||||||
if (domTests.areDOMPropertiesConfigurable()) {
|
assert.equal(link.href, 'http:///foobar.html');
|
||||||
assert.equal(baseURI, 'http:///dummy.html');
|
}
|
||||||
}
|
},
|
||||||
},
|
}, done);
|
||||||
}, done);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should rewrite links in dynamically injected <a> tags', function (done) {
|
describe('base URL overrides', function () {
|
||||||
runWombatTest({
|
it('document.baseURI should return the original URL', function (done) {
|
||||||
initScript: function () {
|
runWombatTest({
|
||||||
wbinfo = {
|
initScript: function () {
|
||||||
wombat_opts: {},
|
wbinfo = {
|
||||||
prefix: window.location.origin,
|
wombat_opts: {},
|
||||||
wombat_ts: '',
|
prefix: window.location.origin,
|
||||||
};
|
wombat_ts: '',
|
||||||
},
|
};
|
||||||
wombatScript: wombatScript,
|
},
|
||||||
html: '<a href="foobar.html" id="link">A link</a>',
|
wombatScript: wombatScript,
|
||||||
testScript: function () {
|
testScript: function () {
|
||||||
var link = document.getElementById('link');
|
var baseURI = document.baseURI;
|
||||||
if (domTests.areDOMPropertiesConfigurable()) {
|
if (typeof baseURI !== 'string') {
|
||||||
assert.equal(link.href, 'http:///foobar.html');
|
throw new Error('baseURI is not a string');
|
||||||
}
|
}
|
||||||
},
|
if (domTests.areDOMPropertiesConfigurable()) {
|
||||||
}, done);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -379,11 +379,16 @@ var wombat_internal = function($wbwindow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object.defineProperty(obj, prop, {
|
var descriptor = {
|
||||||
configurable: false,
|
configurable: true,
|
||||||
set: set_func,
|
get: get_func,
|
||||||
get: get_func
|
};
|
||||||
});
|
|
||||||
|
if (set_func) {
|
||||||
|
descriptor.set = set_func;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(obj, prop, descriptor);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user