Enhance short-id deserialization and improve test coverage#1438
Enhance short-id deserialization and improve test coverage#1438grill-glitch wants to merge 6 commits into
Conversation
…ll/empty/seq → empty string)
- Reorder serde imports to comply with case-sensitive ASCII ordering - Validate sequence length in visit_seq: error on multi-element sequences instead of silently discarding extra values
…t_id The deserialize_short_id function uses fmt::Formatter and fmt::Result with the fmt:: prefix, but only Display and Formatter were imported. Adding self to the fmt import makes the fmt module available as a path prefix. Fixes compilation error: cannot find module or crate 'fmt' in this scope
- Add unit tests for deserialize_short_id: - plain string, null, tilde (~), empty string - hex string, empty seq, single-element seq - single-element empty string seq - multi-element seq rejection (2 and 3 elements) - missing field (default) - Add integration tests for RealityOpt within OutboundVless: - short-id as string, null, seq, missing - reality-opts absent entirely - multi-value seq rejected at OutboundVless level
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds custom YAML deserialization for Reality configuration's ChangesReality short-id deserialization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
What does this PR do?
Problem
Config parser currently expects
reality.short-idto be a string. If users writeshort-id:(empty key) or an empty YAML sequence, serde errors with "invalid type: sequence, expected a string".Fix
Add a custom serde deserializer that accepts string / null / unit / empty sequence and normalizes empty cases to
""(empty string). Existing non-empty short-id behavior unchanged.Rationale
Improves UX and tolerates common YAML styles; downstream
hex::decode("")already returns emptyVec<u8>, so behavior is consistent.Changes
clash-lib/src/config/internal/proxy.rs: addeddeserialize_short_idcustom deserializer and annotatedRealityOpt.short_idwith#[serde(deserialize_with = "deserialize_short_id", default)]Type
Checklist
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests