Skip to content

refactor(c14n): extract shared namespace-declaration pipeline into a common helper #7

@coderabbitai

Description

@coderabbitai

Summary

The namespace-declaration pipeline in src/c14n/ns_inclusive.rs and src/c14n/ns_exclusive.rs contains duplicated filter/sort/render logic. This duplication introduces drift risk and makes future maintenance harder.

Proposed Refactoring

Extract the shared pipeline into a common helper function that accepts a prefix filter predicate:

  • Inclusive C14N: predicate accepts all in-scope namespace bindings.
  • Exclusive C14N: predicate accepts only visibly-utilized namespaces (plus any forced prefixes from the InclusiveNamespaces PrefixList).

The helper would own the shared steps:

  1. Collect candidate namespace bindings for the current element.
  2. Apply the caller-supplied predicate to filter them.
  3. Suppress redundant declarations already present in the nearest output ancestor (parent_rendered).
  4. Handle xmlns="" undeclaration semantics.
  5. Sort declarations by prefix (empty prefix first, then lexicographic).
  6. Return the declarations list and the updated rendered map.

Both InclusiveNsRenderer and ExclusiveNsRenderer would delegate to this helper, keeping only their predicate logic local.

Motivation

  • Removes code duplication between the two renderers.
  • Reduces risk of the two implementations drifting apart on shared semantics (e.g., sorting order, xmlns="" suppression rules).
  • Makes it easier to add C14N 1.1 or other future modes.

References

Out of Scope for PR #6

This is a follow-up refactoring task and was explicitly deferred from PR #6.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions