Two Canonical XML transforms still recursed one native frame per element level, so a deeply-nested document overflowed the stack. The C14N 2.0 sequential prefix rewrite walks the tree twice. Its assign pass (which records one canonical prefix per namespace in document order) is now an iterative pre-order walk; its rebuild pass is now a child-gathering accumulator driven by an explicit work stack, threading the in-scope declarations and the root flag down per element. The document-order prefix assignment and the root-hoisted declarations are unchanged. The node-subset serializer (`canonicalize(_:including:)`) now drives the same deferred-close work stack as the main serializer, threading each element's in-scope and rendered namespace context; an omitted element still passes its declarations to descendants without rendering or a close tag. The canonical bytes are unchanged: the C14N exclusive, 2.0, and node-subset corpora pass (1794 tests). A 50000-deep document now rewrites and subset-canonicalizes without crashing, guarded by `CanonicalDepthSafetyTests`. Part of #350.
9 lines
416 B
Swift
9 lines
416 B
Swift
/// One step of the iterative canonical node-subset serialization (C14N over a
|
|
/// selected subtree): a `TreeNode` to emit with its in-scope and already-rendered
|
|
/// namespace context, or a deferred element close. The mutable-tree counterpart
|
|
/// to ``CanonicalStep``.
|
|
enum CanonicalSelectedStep {
|
|
case open(PureXML.Model.TreeNode, inScope: [String: String], rendered: [String: String])
|
|
case close(String)
|
|
}
|