Skip to content

Fix Reject URL Regex: 避免 URL-REGEX 中使用逗号 - #114

Merged
SukkaW merged 2 commits into
SukkaW:masterfrom
Goooyi:fix-url-regex-comma
Oct 26, 2026
Merged

SukkaW merged 2 commits into
SukkaW:masterfrom
Goooyi:fix-url-regex-comma

Conversation

@Goooyi

@Goooyi Goooyi commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

问题

Surge 按逗号分割规则字段。Source/non_ip/reject-url-regex.conf 中这两条 URL-REGEX 的 \d{1,3} 含有逗号,正则被截断为 ^http://\d{1:

URL-REGEX,^http://\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/(adgateway|adv)/
URL-REGEX,^http://\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/(EcomResourceServer/AdPlayPage/adinfo|MobileAdServer/)

Surge Mac 6.10.0 每次加载 https://ruleset.skk.moe/List/non_ip/reject-url-regex.conf 都会记录:

[NSRegularExpression] Invalid regular expression, this rule will never match: ^http://\d{1 (The value "^http://\d{1" is invalid. (NSCocoaErrorDomain:2048))

因此这两条规则从未生效。

修改

将这两行中的 \d{1,3} 改为 \d+,不再含逗号,语义基本一致(只是不再限制每段 1–3 位)。

验证

在 Surge Mac 6.10.0 上用改写后的规则测试,http://1.2.3.4/adgateway/x 可被正确匹配为 REJECT,且不再出现上述 Invalid regular expression 警告。

🤖 Generated with Claude Code

https://claude.ai/code/session_013iWLB8qbvZ5YkLEahpL6iy

Surge splits rule fields on commas, so \d{1,3} truncated these two
regexes to ^http://\d{1 and they never matched. Use \d+ instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013iWLB8qbvZ5YkLEahpL6iy

@SukkaW SukkaW left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we still need to ensure this only matches to something at least somewhat resembles an actual IP.

\d+ can't bail out https://2026.10.26.1257.example.com/ earlier (when 4 digit subdomain should bail out quickly).

Per review: \d+ cannot bail out early on hosts like 2026.10.26.1257.example.com.
\d\d?\d? keeps each label to 1-3 digits and contains no comma.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013iWLB8qbvZ5YkLEahpL6iy
@Goooyi

Goooyi commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, good point. Updated to \d\d?\d? (1–3 digits per label, still comma-free), so it bails out on 4-digit labels again.

Tested with Surge Mac 6.10.0 rule match:

  • http://1.2.3.4/adgateway/x, http://123.45.6.78/MobileAdServer/a → matched
  • http://2026.10.26.1257.example.com/adgateway/x, http://1234.5.6.7/adv/x, http://12.34.56.78/normal/page → not matched
  • no "Invalid regular expression" warning for these two rules

@SukkaW SukkaW left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM then. In the meantime I will add more validation to detect , in URL-REGEX during ruleset output here.

@SukkaW
SukkaW merged commit 2b3f4e2 into SukkaW:master Oct 26, 2026
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

Successfully merging this pull request may close these issues.

2 participants