Skip to content

Convert SwitchyOmega IpCondition imports into internal CIDR-backed host regex rules#542

Merged
salarcode merged 3 commits into
masterfrom
copilot/fix-ip-condition-conversion
May 19, 2026
Merged

Convert SwitchyOmega IpCondition imports into internal CIDR-backed host regex rules#542
salarcode merged 3 commits into
masterfrom
copilot/fix-ip-condition-conversion

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

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 usable RegexHost rules. 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

    • Replace RuleImporterSwitchy's IpCondition compile/analyze path with direct CIDR parsing and Utils.ipCidrNotationToRegExp generation.
    • Preserve imported Ip: rules as internal RegexHost rules instead of relying on SwitchyOmega’s PAC-oriented subnet helpers.
  • IPv6 host normalization

    • Fix Utils.normalizeIpForMatching to preserve the final hextet in compressed IPv6 addresses.
    • Strip bracketed ports ([2001:db8::1]:443) without misclassifying the last IPv6 segment as a port.
  • Rule matching

    • Add normalized-IP fallback for RegexHost evaluation in ProxyRules, so imported IPv6 CIDR regexes match runtime hosts after canonicalization.
  • Regression coverage

    • Add coverage for:
      • IPv4 CIDR imports
      • bracketed IPv4 CIDR forms from SwitchyOmega exports
      • IPv6 /128 imports
      • compressed/bracketed IPv6 host matching after import

Example of supported import input after this change:

[SwitchyOmega Conditions]
Ip: 10.0.0.0/8
Ip: [172.16.0.0/12]
Ip: 192.168.0.0/16
Ip: 2001:db8::1/128
*.github.com

Imported IPv6 rules now normalize and match equivalent runtime hosts such as:

Utils.normalizeIpForMatching('[2001:db8::1]:443')
// => 2001:0db8:0000:0000:0000:0000:0000:0001

Copilot AI and others added 2 commits May 19, 2026 00:40
Agent-Logs-Url: https://github.com/salarcode/SmartProxy/sessions/2aebb3db-e193-47b4-bc2d-a3a1042bb183

Co-authored-by: salarcode <1272095+salarcode@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 IpCondition analyze/compile/fromStr logic in RuleImporterSwitchy.js with a direct CIDR→RegExp path; match against normalized hosts.
  • Fix Utils.normalizeIpForMatching to preserve the trailing IPv6 hextet and properly strip bracketed ports; add a normalized-IP fallback in ProxyRules for RegexHost evaluation.
  • 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.

Comment thread src/lib/RuleImporterSwitchy.js
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@salarcode salarcode marked this pull request as ready for review May 19, 2026 01:59
@salarcode salarcode merged commit 03748c5 into master May 19, 2026
3 checks passed
@salarcode salarcode deleted the copilot/fix-ip-condition-conversion branch May 19, 2026 02:02
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.

3 participants