testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Hammerhead crashes if DOM contains iframes with quotes in name attribute

Open martinkutter opened this issue 1 year ago • 3 comments

What is your Scenario?

DOM contains an iframe like

<iframe src="https://example.com" name='my "example" page'/>

What is the Current behavior?

If i run any test, hammerhead crashes with: Failed to execute 'querySelectorAll' on 'Document': '*[target="my "example" page"]' is not a valid selector.

What is the Expected behavior?

hammerhead handles this special case of name attributes correct

What is your public website URL? (or attach your complete example)

https://crs7fr.csb.app/

What is your TestCafe test code?

fixture(`Iframe`).page("https://crs7fr.csb.app/");

test("iframe input exists", async (t) => {
    await t.expect(Selector(`[data-test-id="iframe"]`).count).eql(1);
});

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

  1. run example test provided above

TestCafe version

1.18.4

Node.js version

No response

Command-line arguments

Browser name(s) and version(s)

No response

Platform(s) and version(s)

No response

Other

No response

martinkutter avatar Jul 26 '22 12:07 martinkutter

Could be fixed by changing https://github.com/DevExpress/testcafe-hammerhead/blob/master/src/client/sandbox/node/element.ts#L960 to

const elementsWithTarget = nativeMethods.querySelectorAll.call(this.document, `*[target="${iframe.name.replaceAll('"', '\\"')}"]`); 

martinkutter avatar Jul 26 '22 12:07 martinkutter

I was able to reproduce the issue. Moreover, I confirm that your fix solves the described problem. If you want, you can create a PR with the suggested fix. We will review it.

AlexKamaev avatar Jul 27 '22 06:07 AlexKamaev

fixed by https://github.com/DevExpress/testcafe-hammerhead/pull/2788

martinkutter avatar Jul 27 '22 15:07 martinkutter