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

Safari (WebKit): "SyntaxError: Invalid regular expression: invalid group specifier name" #184

Open
MurakamiShinyu opened this issue May 14, 2022 · 2 comments

Comments

@MurakamiShinyu
Copy link
Member

MurakamiShinyu commented May 14, 2022

https://vivliostyle-pub-develop.vercel.app not working in Safari (WebKit).

Safari (WebKit)でVivliostyle Pubが動きません。コンソールを確認すると、SyntaxErrorが発生しています:

SyntaxError: Invalid regular expression: invalid group specifier name

これはWebKItで正規表現の後読み(lookbehind)が未サポートであるために起きるエラーです。WebKitのissue:

  • Bug 174931 - Implement RegExp lookbehind assertions

問題の正規表現のコードは .replace(/(?<!^)\/+/g,"/") というところで使われています。
これは、Vivliostyle Pubのソースコードではなく、Webpackでバンドルされている依存ライブラリのひとつである upath の中のコードです。

https://github.com/anodynos/upath/blob/7419429d66f28f860f12f6e4cc9734f6be87f88f/source/code/upath.coffee#L13-L16

toUnix = (p) ->
  p = p.replace /\\/g, '/'
  p = p.replace /(?<!^)\/+/g, '/' # replace doubles except beginning for UNC path
  p

この正規表現の後読みが使われているために、このライブラリを使っているとWebKitでエラーになってしまうという困った問題です。

この問題のコードは、私がupathにpull requestしたものでした😅

@MurakamiShinyu MurakamiShinyu changed the title Safari (WebKit)で動かない: "SyntaxError: Invalid regular expression: invalid group specifier name" Safari (WebKit): "SyntaxError: Invalid regular expression: invalid group specifier name" May 16, 2022
@MurakamiShinyu
Copy link
Member Author

I made a pull request to upath for fixing this issue:

@MurakamiShinyu
Copy link
Member Author

問題のupathを取り除いても、vfm でも同様に正規表現のlookbehindが使われているため、Safariでのこのエラーは解決しません。

vfmで正規表現のlookbehindが使われている箇所:

https://github.com/vivliostyle/vfm/blob/d58f54c4c2cd37457d338117b506094efa4c68e1/src/plugins/math.ts#L15-L18

https://github.com/vivliostyle/vfm/blob/d58f54c4c2cd37457d338117b506094efa4c68e1/src/plugins/ruby.ts#L13

Safariでのエラー(upathは問題が起きる前のバージョン v1.2.0 に変えてテスト):

Screen Shot 2022-06-03 at 22 18 09

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

1 participant