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 DevExpress#620)
  • Loading branch information
LavrovArtem committed Nov 28, 2016
1 parent bb719bd commit 0e789f7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
14 changes: 14 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 _canAccessorsRedirect (window, instruction, owner) {
try {
return owner && owner[INTERNAL_PROPS.processedContext] &&
owner[INTERNAL_PROPS.processedContext] !== window &&
owner[INTERNAL_PROPS.processedContext][instruction];
}
catch (e) {
return false;
}
}

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

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

if (PropertyAccessorsInstrumentation._canAccessorsRedirect(window, INSTRUCTION.setProperty, owner))
return owner[INTERNAL_PROPS.processedContext][INSTRUCTION.setProperty](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 0e789f7

Please sign in to comment.