@@ -4,10 +4,9 @@ import type { FormApi } from '@douyinfe/semi-ui/lib/es/form';
44import { css } from '@emotion/css' ;
55import { useRequest } from 'ahooks' ;
66import { RE2JS } from 're2js' ;
7- import React , { useEffect , useMemo , useRef } from 'react' ;
7+ import { useEffect , useMemo , useRef } from 'react' ;
88import { RULE_TYPE } from '@/share/core/constant' ;
99import { prefs } from '@/share/core/prefs' ;
10- import { detectRunner } from '@/share/core/rule-utils' ;
1110import type { Rule } from '@/share/core/types' ;
1211import { t } from '@/share/core/utils' ;
1312import Api from '@/share/pages/api' ;
@@ -51,7 +50,16 @@ const Edit = ({ visible, rule: ruleProp, onClose }: EditProps) => {
5150 throw new Error ( t ( 'match_rule_empty' ) ) ;
5251 }
5352 if ( rule . condition . regex ) {
54- RE2JS . compile ( rule . condition . regex ) ;
53+ try {
54+ RE2JS . compile ( rule . condition . regex ) ;
55+ } catch ( e ) {
56+ if ( ENABLE_WEB_REQUEST ) {
57+ new RegExp ( rule . condition . regex ) ;
58+ rule . forceRunner = 'web_request' ;
59+ } else {
60+ throw e ;
61+ }
62+ }
5563 }
5664 if (
5765 [
@@ -62,7 +70,11 @@ const Edit = ({ visible, rule: ruleProp, onClose }: EditProps) => {
6270 'domain' ,
6371 'regex' ,
6472 'resourceTypes' ,
65- ] . every ( x => typeof rule . condition ! [ x ] === 'undefined' )
73+ ] . every (
74+ x =>
75+ typeof rule . condition ! [ x as keyof Rule [ 'condition' ] ] ===
76+ 'undefined' ,
77+ )
6678 ) {
6779 throw new Error ( t ( 'match_rule_empty' ) ) ;
6880 }
0 commit comments