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

YAML highlighter crashes in Safari #927

Open
3 tasks done
bengry opened this issue Feb 11, 2025 · 2 comments
Open
3 tasks done

YAML highlighter crashes in Safari #927

bengry opened this issue Feb 11, 2025 · 2 comments

Comments

@bengry
Copy link

bengry commented Feb 11, 2025

Validations

Describe the bug

When using Safari (I tried on v18.3, but I'm pretty sure it also happens on all other versions), even a simple YAML fails to highlight.

When calling codeToHtml you get this error:

Invalid regular expression: invalid range in character class for Unicode pattern.

Other browsers work fine (tested Chromium and Firefox).

Reproduction

https://stackblitz.com/edit/sb1-82zdjs3y?file=src%2FApp.tsx

@slevithan
Copy link
Collaborator

Other browsers work fine (tested Chromium and Firefox).

I also verified your repro link and the grammar playground with YAML work for me in Chrome.

I don't have access to a Mac/Safari for testing. Are you able to identify the specific regex that is throwing this error?

When using Safari (I tried on v18.3, but I'm pretty sure it also happens on all other versions), even a simple YAML fails to highlight. [...]

Invalid regular expression: invalid range in character class for Unicode pattern.

It would be helpful to verify that the problem also exists in older (but recent) versions of Safari, and that this wasn't a weird regression in v18.3.

@bengry
Copy link
Author

bengry commented Feb 12, 2025

I don't have access to a Mac/Safari for testing.

I think you can get a Windows build of WebKit following this, and surely with Playwright (for both Linux/Windows).

Are you able to identify the specific regex that is throwing this error?

Sure - all of these seem to fail:
(?=(?:[^\s[-?:,\[\]{}#&*!|>'"%@`]]|[?:-]\S)([^\s:]|:\S|\s+(?![#\s]))*\s*:(\s|$))
^\\s[-?:,\\[\\]{}#&*!|>'\"%@`]]|[?:-]\\S
[^\\s[-?:,\\[\\]{}#&*!|>'\"%@`]]|[?:-][^\\s[\\[\\]{},]]

Pasting these three into regex101.com shows that the first and last indeed have this error. I'm not sure why Safari threw an error on the second one.

It would be helpful to verify that the problem also exists in older (but recent) versions of Safari, and that this wasn't a weird regression in v18.3.

The repro is after we've had this happen in production, so luckily I have some stats from Sentry to report back - I see these versions: 18.2, 18.3, 18.1.1, 18.1, 17.6.
I can't easily tell if the issue exists from before that since Safari isn't the usual evergreen browser, as you probably know.

I've also simplified the repro - removed React and other stuff, just a plain JS file basically, running the same code, with forgiving: true, and outputting to the console on each failure editing this code, such that I have a console.error in the catch. This is the result in Safari:
Image

You can see this repro (which includes sourcemaps) deployed here, for easier debugging maybe.

P.S.
I also found https://www.browserling.com, which allows using Safari online (free up to ~3 minutes each session, unfortunately).
You can browse the aforementioned very minimal repro directly here.

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

No branches or pull requests

2 participants