From 137c10217a2dfdfcf692f3e51e3aa803bc8cf71a Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 25 Apr 2018 12:37:35 +0300 Subject: [PATCH] fix `Hammerhead overrides some attributes, that are used in non-standard way, with "null"` (close #2347) (#1583) --- src/client/utils/html.js | 2 +- .../sandbox/code-instrumentation/getters-test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/client/utils/html.js b/src/client/utils/html.js index 18d2ad8d49..b61e365eb2 100644 --- a/src/client/utils/html.js +++ b/src/client/utils/html.js @@ -135,7 +135,7 @@ export function cleanUpHtml (html) { find(container, STORED_ATTRS_SELECTOR, el => { for (const { attr, storedAttr } of ATTRS_DATA_FOR_CLEANING) { - if (el.hasAttribute(attr)) + if (el.hasAttribute(attr) && el.hasAttribute(storedAttr)) nativeMethods.setAttribute.call(el, attr, nativeMethods.getAttribute.call(el, storedAttr)); else if (attr === 'autocomplete') nativeMethods.removeAttribute.call(el, attr); diff --git a/test/client/fixtures/sandbox/code-instrumentation/getters-test.js b/test/client/fixtures/sandbox/code-instrumentation/getters-test.js index c3b268c744..fe005d71e4 100644 --- a/test/client/fixtures/sandbox/code-instrumentation/getters-test.js +++ b/test/client/fixtures/sandbox/code-instrumentation/getters-test.js @@ -440,3 +440,15 @@ test('getProperty function should not throw an error for document.all property ( ok(false); } }); + +test('leaving attributes, that are used in non-standard way, as they are (GH-2347)', function () { + var htmlText = ''; + var div = document.createElement('div'); + + setProperty(div, 'innerHTML', htmlText); + + var a = div.firstChild; + + strictEqual(a.outerHTML, processHtml(htmlText)); + strictEqual(getProperty(a, 'outerHTML'), htmlText); +});