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

SyntaxError: Invalid regular expression in Safari #142

Open
robin-hartmann opened this issue May 19, 2022 · 3 comments
Open

SyntaxError: Invalid regular expression in Safari #142

robin-hartmann opened this issue May 19, 2022 · 3 comments

Comments

@robin-hartmann
Copy link

robin-hartmann commented May 19, 2022

Since version 4.0.5 or, to be more precise, since commit 6adcb7d, both formdata-to-blob.js and esm.min.js fail to load in Safari with the error SyntaxError: Invalid regular expression: invalid group specifier name. This is due to the fact that commit 6adcb7d introduced regular expressions for eol normalization, which use lookbehind (?<!).

Sadly, Safari still doesn't support lookbehind in regular expressions. And even worse, this error doesn't happen when the offending code is being executed, but instead, it already happens when the source file containing it is being parsed, which in turn prevents execution of any code in the same source file. I.e., the error happens, even if the offending code is not even being used.

@robin-hartmann
Copy link
Author

robin-hartmann commented May 19, 2022

I believe this could be fixed by using the regular expression from normalizeLinefeeds in FormData.js, which achieves the same result without lookbehind. I already tried it out and the tests still pass without problems.

@jimmywarting
Copy link
Owner

I already tried it out and the tests still pass without problems.

could you share what you have tried?


...wondering why you even use this package at all in the browser... all browser already have support for FormData already.

@robin-hartmann
Copy link
Author

robin-hartmann commented May 20, 2022

I already tried it out and the tests still pass without problems.

could you share what you have tried?

I replaced the offending regular expressions in formdata-to-blob.js and esm.min.js (replace(/\r(?!\n)|(?<!\r)\n/g, '\r\n')) with the one from normalizeLinefeeds in FormData.js (replace(/\r?\n|\r/g, '\r\n')).

...wondering why you even use this package at all in the browser... all browser already have support for FormData already.

I came across this problem more or less by accident and I thought I should at least open an issue, even if it isn't really relevant for my project. It might be relevant for someone else.

If you really want to know, my project is using node-fetch, which depends on this package. Because my project is a hybrid web app, which deploys the exact same code for Electron (macOS, Windows) and Cordova (Android, iOS), this package's code is not only loaded in Chrome (Android, Electron), but also in Safari. The code is only used on Electron, but as I described in the first post, the error happens even if the code isn't actually being used. For now, I've worked around it by splitting node-fetch and all of its dependencies into its own source file, which is only loaded on Electron.

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