Conversation
…_common - Add collect_ns_declarations() helper that owns the shared pipeline: xml: prefix filtering, redundant declaration suppression, spurious xmlns="" handling, prefix sorting, and rendered map update - InclusiveNsRenderer and ExclusiveNsRenderer now delegate to the helper with mode-specific predicate (accept-all vs visibly-utilized) - Removes ~90 lines of duplicated logic between the two renderers Closes #7
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughExtracted shared namespace-declaration collection logic into a new internal helper Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
Pull request overview
Refactors the C14N namespace rendering implementation by extracting the shared namespace-declaration pipeline (filter/suppress/sort/update) into a common helper, so inclusive/exclusive renderers only supply mode-specific selection logic.
Changes:
- Added
ns_common::collect_ns_declarations()to centralize namespace declaration collection/suppression/sorting and rendered-map updates. - Updated
InclusiveNsRendererandExclusiveNsRendererto delegate to the shared helper with mode-specific predicates. - Wired the new module into
src/c14n/mod.rsand added focused unit tests for the shared pipeline.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/c14n/ns_inclusive.rs |
Replaces the inline inclusive namespace pipeline with a call to collect_ns_declarations using an accept-all predicate. |
src/c14n/ns_exclusive.rs |
Replaces the inline exclusive namespace pipeline with a call to collect_ns_declarations using a visibly-utilized/forced-prefix predicate. |
src/c14n/ns_common.rs |
Introduces the shared pipeline helper and adds unit tests for filtering/suppression/sorting behavior. |
src/c14n/mod.rs |
Registers the new ns_common module in the C14N module tree. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/c14n/ns_common.rs (1)
95-167: Consider anode_setregression too.The new cases cover full-document paths, but the subtle branch here is the
xmlns=""case when output ancestors are omitted from the subset. A focused test throughcanonicalize'snode_setpath would pin the behaviorhas_in_scope_default_namespace(node)is protecting.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/c14n/ns_common.rs` around lines 95 - 167, Tests exercise collect_ns_declarations but miss the canonicalize node_set path where omission of ancestor nodes can change handling of xmlns=""; add a focused test that calls canonicalize with a node_set (not full-document) to reproduce the regression and ensure has_in_scope_default_namespace(node) still forces emitting xmlns="" when an ancestor default-namespace is not present in the node_set; specifically, write a test that builds a document with a default namespace on the root and a child that undeclares it (xmlns=""), then call canonicalize with node_set containing only the child and assert the output includes xmlns="" (or that canonicalize emits the undeclaration), referencing canonicalize, node_set, and has_in_scope_default_namespace to locate the affected code paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/c14n/ns_common.rs`:
- Around line 95-167: Tests exercise collect_ns_declarations but miss the
canonicalize node_set path where omission of ancestor nodes can change handling
of xmlns=""; add a focused test that calls canonicalize with a node_set (not
full-document) to reproduce the regression and ensure
has_in_scope_default_namespace(node) still forces emitting xmlns="" when an
ancestor default-namespace is not present in the node_set; specifically, write a
test that builds a document with a default namespace on the root and a child
that undeclares it (xmlns=""), then call canonicalize with node_set containing
only the child and assert the output includes xmlns="" (or that canonicalize
emits the undeclaration), referencing canonicalize, node_set, and
has_in_scope_default_namespace to locate the affected code paths.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cfd69caa-8ef5-4723-bc6e-5b8aaba1196a
📒 Files selected for processing (4)
src/c14n/mod.rssrc/c14n/ns_common.rssrc/c14n/ns_exclusive.rssrc/c14n/ns_inclusive.rs
Enables monomorphization and inlining of the predicate closure, eliminating dynamic dispatch overhead on each namespace binding.
There was a problem hiding this comment.
Pull request overview
Refactors the XML C14N namespace-declaration rendering logic by extracting the shared “collect/filter/suppress/sort/update” pipeline into a new common helper, reducing duplication between inclusive and exclusive namespace renderers.
Changes:
- Added
ns_common::collect_ns_declarations()to own the shared namespace-declaration pipeline. - Updated
InclusiveNsRendererandExclusiveNsRendererto delegate to the shared helper with mode-specific predicates. - Introduced focused unit tests for the shared helper covering key pipeline behaviors.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/c14n/ns_inclusive.rs |
Replaces inline pipeline with a call into the shared helper using an accept-all predicate. |
src/c14n/ns_exclusive.rs |
Replaces inline pipeline with a call into the shared helper using the visibly-utilized / forced-prefix predicate. |
src/c14n/ns_common.rs |
New shared helper implementing the namespace-declaration pipeline plus new unit tests. |
src/c14n/mod.rs |
Registers the new ns_common module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
Re: CodeRabbit nitpick — This path is already covered by two pre-existing integration tests in
Both tests pass through the refactored |
Summary
InclusiveNsRendererandExclusiveNsRendererinto a sharedcollect_ns_declarations()helper in newns_commonmoduleTechnical Details
The shared helper owns the full pipeline:
xml:prefix filtering → mode predicate → redundant declaration suppression (parent_rendered) → spuriousxmlns=""handling → prefix sorting → rendered map update.The predicate is accepted as
impl Fn(&str, &str) -> bool, enabling monomorphization and inlining — no dynamic dispatch overhead per namespace binding.The only mode-specific logic remains local to each renderer:
|_, _| true(all in-scope bindings)utilized.contains(prefix) || inclusive_prefixes.contains(prefix)Known Limitations
Test Plan
ns_commoncovering: xml prefix exclusion, sorting, redundant suppression, spurious xmlns="" suppression, undeclaration emission, predicate filteringnode_setsubset path (wherehas_in_scope_default_namespaceforcesxmlns=""emission when output ancestors are excluded) is already covered by two pre-existing integration tests:subset_xmlns_empty_with_excluded_default_ns_ancestorandsubset_no_spurious_xmlns_emptyintests/c14n_integration.rs-D warningsCloses #7