diff --git a/lib/generator/__tests__/template.test.ts b/lib/generator/__tests__/template.test.ts index ade7ffbde..a37d05891 100644 --- a/lib/generator/__tests__/template.test.ts +++ b/lib/generator/__tests__/template.test.ts @@ -204,6 +204,10 @@ test('convertNewSurgeScriptRuleToQuantumultXRewriteRule', t => { convertNewSurgeScriptRuleToQuantumultXRewriteRule('zhihu people = type=http-request,pattern=https://api.zhihu.com/people/,script-path=https://raw.githubusercontent.com/onewayticket255/Surge-Script/master/surge%20zhihu%20people.js'), 'https://api.zhihu.com/people/ url script-request-header https://raw.githubusercontent.com/onewayticket255/Surge-Script/master/surge%20zhihu%20people.js' ); + t.is( + convertNewSurgeScriptRuleToQuantumultXRewriteRule('JD = requires-body=1,max-size=0,script-path= https://raw.githubusercontent.com/NobyDa/Script/master/JD-DailyBonus/JD_DailyBonus.js,type=http-response,pattern=^https?://api\.m\.jd\.com/client\.action\?functionId=(start|signBean)'), + '^https?://api\.m\.jd\.com/client\.action\?functionId=(start|signBean) url script-response-body https://raw.githubusercontent.com/NobyDa/Script/master/JD-DailyBonus/JD_DailyBonus.js' + ); t.is( convertNewSurgeScriptRuleToQuantumultXRewriteRule('zhihu people = type=unknown-type'), '' diff --git a/lib/generator/template.ts b/lib/generator/template.ts index fc3508de9..9906b2436 100644 --- a/lib/generator/template.ts +++ b/lib/generator/template.ts @@ -164,7 +164,7 @@ export const convertSurgeScriptRuleToQuantumultXRewriteRule = (str: string): str }; export const convertNewSurgeScriptRuleToQuantumultXRewriteRule = (str: string): string => { - const matched = str.match(/([\w\s]+)=(.+)/); + const matched = str.match(/^(.+?)=(.+?)$/); const result: string[] = []; if (!matched) { @@ -178,7 +178,6 @@ export const convertNewSurgeScriptRuleToQuantumultXRewriteRule = (str: string): const isRequireBody = 'requires-body' in params; if (isRequireBody) { - // parts[1] => Effective URL Rule result.push(params.pattern as string, 'url', 'script-response-body', params['script-path'] as string); } else { result.push(params.pattern as string, 'url', 'script-response-header', params['script-path'] as string); @@ -190,7 +189,6 @@ export const convertNewSurgeScriptRuleToQuantumultXRewriteRule = (str: string): const isRequireBody = 'requires-body' in params; if (isRequireBody) { - // parts[1] => Effective URL Rule result.push(params.pattern as string, 'url', 'script-request-body', params['script-path'] as string); } else { result.push(params.pattern as string, 'url', 'script-request-header', params['script-path'] as string); diff --git a/lib/utils/index.ts b/lib/utils/index.ts index d2d16af1e..88c8644b8 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -1208,8 +1208,14 @@ export const pickAndFormatStringList = (obj: object, keyList: readonly string[]) export const decodeStringList = >(stringList: ReadonlyArray): T => { const result = {}; stringList.forEach(item => { - const pair = item.split('='); - result[pair[0]] = pair[1] || true; + if (item.includes('=')) { + const match = item.match(/^(.*?)=(.*?)$/); + if (match) { + result[match[1].trim()] = match[2].trim() || true; + } + } else { + result[item.trim()] = true; + } }); return result as T; };