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

Pattern works in Chrome, but not jsdom #3680

Open
stnguyen90 opened this issue Feb 9, 2024 · 0 comments · May be fixed by #3681
Open

Pattern works in Chrome, but not jsdom #3680

stnguyen90 opened this issue Feb 9, 2024 · 0 comments · May be fixed by #3681

Comments

@stnguyen90
Copy link

Basic info:

  • Node.js version: v20.8.0
  • jsdom version: 24.0.0

Minimal reproduction case

const jsdom = require('jsdom');
const { JSDOM } = jsdom;

const pattern = String.raw`^(?!-)[[A-Za-z0-9\-]]+([[\-\.]]{1}[[a-z0-9]]+)*\.[[A-Za-z]]{2,18}$`;
const value = 'not-a-domain';
const dom = new JSDOM(`<input id="domain" pattern="${pattern}" required value="${value}">`);

const input = dom.window.document.querySelector("#domain");

console.log('pattern:', input.pattern);
console.log('value:', input.value);
input.checkValidity();
console.log('validity.valid:', input.validity.valid); // returns true
console.log('validity.patternMismatch:', input.validity.patternMismatch); // returns false

How does similar code behave in browsers?

In the browser, input.validity.valid is false and input.validity.patternMismatch is true. You can test this by pasting this code:

<input id="domain" pattern="^(?!-)[[A-Za-z0-9\-]]+([[\-\.]]{1}[[a-z0-9]]+)*\.[[A-Za-z]]{2,18}$" required value="not-a-domain">

<input id="domain" pattern="^(?!-)[[A-Za-z0-9\-]]+([[\-\.]]{1}[[a-z0-9]]+)*\.[[A-Za-z]]{2,18}$" required value="example.com">

into MDN's pattern docs:

image

In jsdom's source code, I noticed the u flag being used for the RegExp:

https://github.com/kontomondo/jsdom/blob/c8f6f2504a71aa904f76b5bd4359505fc4820860/lib/jsdom/living/nodes/HTMLInputElement-impl.js#L806

According to MDN:

image

Would it be okay to update the source accordingly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant