Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Tests fail with chrome >= 120 #906

Closed
florian-sanders-cc opened this issue Dec 8, 2023 · 0 comments · Fixed by #907 or #876
Closed

Automatic Tests fail with chrome >= 120 #906

florian-sanders-cc opened this issue Dec 8, 2023 · 0 comments · Fixed by #907 or #876
Assignees
Labels
bug Something isn't working ci/cd maintenance Code refactoring, project structure, dev tooling (storybook, dev server, npm tasks...)

Comments

@florian-sanders-cc
Copy link
Contributor

florian-sanders-cc commented Dec 8, 2023

Context

With chrome >= 120, the i18n-sanitize tests fail.

  filter > Only keep href and title attributes on <a> (remove every other attributes)
      AssertionError: expected 5 to equal 3
      + expected - actual
      
      -5
      +3
      
      at test/i18n-sanitize.test.js:24:47
      at Array.forEach (<anonymous>)
      at compareChildNodes (test/i18n-sanitize.test.js:8:23)
      at o.<anonymous> (test/i18n-sanitize.test.js:98:5)
Explanation Tests fail because the sanitize function adds `target` and `rel` attributes on the sanitized anchor element while it did not with previous chrome versions.

The sanitize function tests if the origin of the sanitized link (node.origin) equals window.location.origin.
If origins are different, it adds the target="_blank" and rel="..." attributes.

It looks like node.origin for a sanitized link with <a href="/foo">toto</toto> now results in an empty string while it resulted to http://localhost... (or whatever) before.

It only happens with anchor elements inside a document fragment, which is what the sanitize function returns.

How to reproduce the root cause of the issue?
const template = document.createElement('template');
template.innerHTML = `<a href="/toto">toto</a>`;

const anchorEl = template.content.querySelector('a');
console.log({ origin: anchorEl.origin })
// with chrome 119, origin = your localhost
// with chrome 120, origin = empty string
@florian-sanders-cc florian-sanders-cc added the bug Something isn't working label Dec 8, 2023
@florian-sanders-cc florian-sanders-cc self-assigned this Dec 8, 2023
florian-sanders-cc added a commit that referenced this issue Dec 8, 2023
This fixes an issue with Chrome > 120.

Fixes #906
@florian-sanders-cc florian-sanders-cc added maintenance Code refactoring, project structure, dev tooling (storybook, dev server, npm tasks...) ci/cd labels Dec 8, 2023
@florian-sanders-cc florian-sanders-cc changed the title Automatic Tests fail with chrome > 120 Automatic Tests fail with chrome >= 120 Dec 8, 2023
florian-sanders-cc added a commit that referenced this issue Dec 11, 2023
This fixes an issue with Chrome > 120.

Fixes #906
florian-sanders-cc added a commit that referenced this issue Dec 11, 2023
This fixes an issue with Chrome > 120.

Fixes #906
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ci/cd maintenance Code refactoring, project structure, dev tooling (storybook, dev server, npm tasks...)
Projects
None yet
1 participant