Convert SwitchyOmega IpCondition imports into internal CIDR-backed host regex rules#542
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/salarcode/SmartProxy/sessions/2aebb3db-e193-47b4-bc2d-a3a1042bb183 Co-authored-by: salarcode <1272095+salarcode@users.noreply.github.com>
Agent-Logs-Url: https://github.com/salarcode/SmartProxy/sessions/2aebb3db-e193-47b4-bc2d-a3a1042bb183 Co-authored-by: salarcode <1272095+salarcode@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
salarcode
May 19, 2026 00:46
View session
There was a problem hiding this comment.
Pull request overview
Reworks SwitchyOmega Ip: condition imports so CIDR ranges (including IPv6) are translated into SmartProxy's internal RegexHost rules via the existing Utils.ipCidrNotationToRegExp path, and aligns IPv6 host normalization/matching so imported rules actually match runtime hosts.
Changes:
- Replace the PAC-oriented
IpConditionanalyze/compile/fromStr logic inRuleImporterSwitchy.jswith a direct CIDR→RegExp path; match against normalized hosts. - Fix
Utils.normalizeIpForMatchingto preserve the trailing IPv6 hextet and properly strip bracketed ports; add a normalized-IP fallback inProxyRulesforRegexHostevaluation. - Add unit and integration test coverage for IPv4/IPv6 CIDR imports and normalized IPv6 matching.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/lib/RuleImporterSwitchy.js | Reimplements IpCondition to emit a CIDR-derived RegExp and reuse host normalization for matching. |
| src/lib/Utils.ts | Fixes IPv6 normalization to keep last hextet and only strip ports from bracketed forms. |
| src/core/ProxyRules.ts | Adds regexHostMatches helper to fall back to normalized-IP matching for RegexHost rules. |
| src/tests/Utils.ipCidr.test.ts | Adds coverage for IPv6 normalization preserving trailing hextet and stripping bracketed ports. |
| src/tests/RuleImporter.test.ts | Adds Switchy Ip: CIDR import test and replaces non-null assertions with explicit guards. |
| src/tests/ProxyRules.test.ts | Verifies imported IPv6 CIDR rules match bracketed runtime hosts after normalization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ed input Agent-Logs-Url: https://github.com/salarcode/SmartProxy/sessions/884f778c-e411-42a2-bd4c-7a16e0f79a97 Co-authored-by: salarcode <1272095+salarcode@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SwitchyOmega
Ip:conditions were not surviving import into SmartProxy’s internal rule model, so CIDR-based IP rules — especially IPv6 forms — could not be represented as usableRegexHostrules. This change routes imported IP conditions through the existing CIDR-to-regex path and aligns host normalization so imported IPv6 rules match compressed and bracketed forms correctly.Import path
RuleImporterSwitchy'sIpConditioncompile/analyze path with direct CIDR parsing andUtils.ipCidrNotationToRegExpgeneration.Ip:rules as internalRegexHostrules instead of relying on SwitchyOmega’s PAC-oriented subnet helpers.IPv6 host normalization
Utils.normalizeIpForMatchingto preserve the final hextet in compressed IPv6 addresses.[2001:db8::1]:443) without misclassifying the last IPv6 segment as a port.Rule matching
RegexHostevaluation inProxyRules, so imported IPv6 CIDR regexes match runtime hosts after canonicalization.Regression coverage
/128importsExample of supported import input after this change:
Imported IPv6 rules now normalize and match equivalent runtime hosts such as: