PureXML/Sources/XPath/Budget.swift
Mihaela Mihaljevic ac85dd36de feat(xpath,xslt,wasm): evaluation budget, tailored collation, WASI runtime proof
PureXML.XPath.Budget is the configurable counterpart of libxml2's
fixed 10M node-set cap (libxml2Compatible preset included), thrown as
a located QueryError instead of a silent refusal, default unbounded.
xsl:sort honors lang with tailored alphabet orders for Polish and
Russian derived from the conformance golds, case-folded. The WASM
gate executes all 985 tests under wasmtime on an actual WASI runtime,
wired into CI; the first run caught a real wasm32 trap (Int is 32
bits there, so format-number's digit extraction trapped at 2^31
despite the 2^53 guard; internals are now Int64 and the xsl:number
bound is platform-correct). Xalan baseline 127 -> 125. Closes #143,
closes #144.
2026-06-11 06:26:13 +02:00

21 lines
891 B
Swift

public extension PureXML.XPath {
/// A protective evaluation budget: the maximum node-set length a query
/// may build. libxml2 enforces a fixed 10M-node cap and refuses larger
/// evaluations outright; PureXML evaluates unbounded by default and
/// lets the caller opt into a budget for untrusted input, failing with
/// a thrown ``QueryError/budgetExceeded(_:)`` instead of a silent
/// refusal. The counter is shared across one evaluation, including
/// nested predicate evaluations.
struct Budget: Sendable {
/// The largest node-set any step or union may produce.
public var maxNodeSetLength: Int
public init(maxNodeSetLength: Int) {
self.maxNodeSetLength = maxNodeSetLength
}
/// The libxml2-compatible cap.
public static let libxml2Compatible = Budget(maxNodeSetLength: 10_000_000)
}
}