From 5fb5e69181e9b7ae86a59ca2ed6acefd78692ccc Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 8 Apr 2022 10:16:55 -0700 Subject: [PATCH] fix: Use of lookbehind regex crashes Safari, added lint rule to prevent future accidental regression --- .eslintrc | 2 ++ package.json | 1 + shared/editor/marks/Italic.ts | 4 ++-- yarn.lock | 8 ++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 7fdd615848..46b29e1334 100644 --- a/.eslintrc +++ b/.eslintrc @@ -16,6 +16,7 @@ "plugin:prettier/recommended" ], "plugins": [ + "es", "@typescript-eslint", "eslint-plugin-import", "eslint-plugin-node", @@ -28,6 +29,7 @@ "curly": 2, "no-mixed-operators": "off", "no-useless-escape": "off", + "es/no-regexp-lookbehind-assertions": "error", "@typescript-eslint/no-unused-vars": [ "error", { diff --git a/package.json b/package.json index 4cfe919add..1c7f29b33e 100644 --- a/package.json +++ b/package.json @@ -287,6 +287,7 @@ "eslint": "^7.6.0", "eslint-config-prettier": "^8.3.0", "eslint-import-resolver-typescript": "^2.5.0", + "eslint-plugin-es": "^4.1.0", "eslint-plugin-import": "^2.25.3", "eslint-plugin-jsx-a11y": "^6.1.0", "eslint-plugin-node": "^11.1.0", diff --git a/shared/editor/marks/Italic.ts b/shared/editor/marks/Italic.ts index 4a361c7b1e..f6a6793946 100644 --- a/shared/editor/marks/Italic.ts +++ b/shared/editor/marks/Italic.ts @@ -46,8 +46,8 @@ export default class Italic extends Mark { * 1_123_ */ return [ - markInputRule(/(?<=[^_\na-zA-Z0-9]|^)_([^_\n]+)_$/, type), - markInputRule(/(?<=[^*\na-zA-Z0-9]|^)\*([^*\n]+)\*$/, type), + markInputRule(/(?:^|[^_a-zA-Z0-9])(_([^_]+)_)$/, type), + markInputRule(/(?:^|[^*a-zA-Z0-9])(\*([^*]+)\*)$/, type), ]; } diff --git a/yarn.lock b/yarn.lock index dd13774aa2..7c238b9888 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6726,6 +6726,14 @@ eslint-plugin-es@^3.0.0: eslint-utils "^2.0.0" regexpp "^3.0.0" +eslint-plugin-es@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-es/-/eslint-plugin-es-4.1.0.tgz#f0822f0c18a535a97c3e714e89f88586a7641ec9" + integrity sha512-GILhQTnjYE2WorX5Jyi5i4dz5ALWxBIdQECVQavL6s7cI76IZTDWleTHkxz/QT3kvcs2QlGHvKLYsSlPOlPXnQ== + dependencies: + eslint-utils "^2.0.0" + regexpp "^3.0.0" + eslint-plugin-import@^2.25.3: version "2.25.3" resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.25.3.tgz#a554b5f66e08fb4f6dc99221866e57cfff824766"