Skip to content

Commit

Permalink
fix 'The href of a link processsed incorrectly in an iframe without s…
Browse files Browse the repository at this point in the history
…rc if it is set from the main window' (close #620) (#757)
  • Loading branch information
LavrovArtem authored and miherlosev committed Dec 16, 2016
1 parent 96aeaa1 commit fde3440
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/client/sandbox/code-instrumentation/properties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,17 @@ export default class PropertyAccessorsInstrumentation extends SandboxBase {
return window[ORIGINAL_WINDOW_ON_ERROR_HANDLER_KEY];
}

static _getSetPropertyInstructionByOwner (owner, window) {
try {
return owner && owner[INTERNAL_PROPS.processedContext] &&
owner[INTERNAL_PROPS.processedContext] !== window &&
owner[INTERNAL_PROPS.processedContext][INSTRUCTION.setProperty];
}
catch (e) {
return null;
}
}

attach (window) {
super.attach(window);

Expand Down Expand Up @@ -837,6 +848,11 @@ export default class PropertyAccessorsInstrumentation extends SandboxBase {
if (typeUtils.isNullOrUndefined(owner))
PropertyAccessorsInstrumentation._error(`Cannot set property '${propName}' of ${typeUtils.inaccessibleTypeToStr(owner)}`);

var ownerSetPropertyInstruction = PropertyAccessorsInstrumentation._getSetPropertyInstructionByOwner(owner, window);

if (ownerSetPropertyInstruction)
return ownerSetPropertyInstruction(owner, propName, value);

if (typeof propName === 'string' && shouldInstrumentProperty(propName) &&
accessors[propName].condition(owner))
return accessors[propName].set(owner, value);
Expand Down
32 changes: 26 additions & 6 deletions test/client/fixtures/sandbox/code-instrumentation/setters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,11 @@ asyncTest('body.innerHTML in iframe', function () {

eval(processScript('iframe.contentDocument.body.innerHTML = "";'));

window.QUnitGlobals.wait(hasShadowUIRoot)
.then(function () {
ok(true);
iframe.parentNode.removeChild(iframe);
start();
});
return window.QUnitGlobals.wait(hasShadowUIRoot);
}).then(function () {
ok(true);
iframe.parentNode.removeChild(iframe);
start();
});
document.body.appendChild(iframe);
});
Expand Down Expand Up @@ -333,6 +332,27 @@ test('outerHTML', function () {

module('regression');

asyncTest('innerHTML in iframe (GH-620)', function () {
var iframe = document.createElement('iframe');
var url = 'somePage.html';
var proxyUrl = urlUtils.getProxyUrl(url, { resourceType: 'i' });

iframe.id = 'test' + Date.now();

window.QUnitGlobals.waitForIframe(iframe)
.then(function () {
eval(processScript('iframe.contentDocument.body.innerHTML = "<a href=\\"' + url + '\\">link</a>";'));

strictEqual(iframe.contentDocument.body.firstChild.href, proxyUrl);

start();

document.body.removeChild(iframe);
});

document.body.appendChild(iframe);
});

test('script block inserted via element.innerHtml must not be executed (B237015)', function () {
var testPropertyName = 'testProperty';
var el = document.createElement('div');
Expand Down

0 comments on commit fde3440

Please sign in to comment.