Skip to content

Commit

Permalink
fix `Hammerhead sets the 'target' attribute to a button after a click…
Browse files Browse the repository at this point in the history
… on it` (close #1437) (#1439)
  • Loading branch information
LavrovArtem authored and churkin committed Jan 16, 2018
1 parent c882ac0 commit 2d30ccd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/client/sandbox/node/element.js
Expand Up @@ -657,9 +657,13 @@ export default class ElementSandbox extends SandboxBase {
}

_ensureTargetContainsExistingBrowsingContext (el) {
if (!nativeMethods.hasAttribute.call(el, 'target'))
return;

const attr = nativeMethods.getAttribute.call(el, 'target');
const storedAttr = nativeMethods.getAttribute.call(el, DomProcessor.getStoredAttrName('target'));

el.setAttribute('target', storedAttr || el.target);
el.setAttribute('target', storedAttr || attr);
}

_setValidBrowsingContextOnElementClick (window) {
Expand Down
13 changes: 12 additions & 1 deletion test/client/fixtures/target-attr-test.js
Expand Up @@ -287,11 +287,22 @@ test('The form in the iframe (GH-880)', function () {
});
});

test('should not add target attribute after click', function () {
test('should not add target attribute after click on the anchor element', function () {
var link = createTestedLink();

provokeTargetCalculation(link);
checkElementTarget(link, '', null);

link.parentNode.removeChild(link);
});

test('should not add target attribute after click on the button element (GH-1437)', function () {
var button = document.createElement('button');

document.body.appendChild(button);

provokeTargetCalculation(button);
checkElementTarget(button, void 0, null);

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

0 comments on commit 2d30ccd

Please sign in to comment.