WIP feat(yang-push): xpath normalization - #7
Open
rodonile wants to merge 5 commits into
Open
Conversation
rodonile
force-pushed
the
xpath-normalization
branch
2 times, most recently
from
August 18, 2026 14:46
ae0cf99 to
06692a6
Compare
rodonile
force-pushed
the
xpath-normalization
branch
from
August 20, 2026 14:23
06692a6 to
28b002b
Compare
rodonile
force-pushed
the
xpath-normalization
branch
2 times, most recently
from
August 25, 2026 15:15
4ee03e6 to
c4de624
Compare
Move find_xpath_prefixes out of xml_utils.rs (a broad, unrelated XML-parsing grab-bag) into a new xpath.rs module, the shared home for XPath 1.0 subset text utilities. Register the module in lib.rs and update its two call sites. Pure refactor, no behavior change. Sets up xpath.rs as the target for the normalize_path engine added next.
Add DatastoreXPathFilter::normalize_path: converts an xpath to RFC 8641's canonical, module-name-qualified, prefix-on-change form (matches libyang's SchemaPathFormat::DATA), whether the source path uses declared xmlns prefixes or bare module-name prefixes. Backed by three new pure helpers in xpath.rs: split_location_path, parse_node_test, is_ncname. Bails to None (caller keeps the original path) for unsupported XPath 1.0 constructs or an unresolvable declared prefix. Not wired into any caller yet.
Apply DatastoreXPathFilter::normalize_path to the datastore xpath filter fetched via get_yang_push_subscription_by_id, so the cached target is always in canonical module-name-qualified form regardless of how the device encoded prefixes (declared xmlns vs. bare module name). Falls back to the original path (with a warning) when the path can't be confidently normalized.
JSON-encoded SubscriptionStarted/Modified notifications carry their datastore-xpath-filter as a plain string with no xmlns table. Normalize it the same way as the NETCONF/XML path, in build_subscription_info, via normalize_json_target_xpath. Needs no schema access: passing an empty namespace table makes normalize_path treat every prefix as already-resolved. Reduces noise in the canonical-form diagnostic and avoids spurious subscription-changed refetches from pure prefix-style variance.
Add check_xpath_target_resolves: after a schema loads, evaluate the subscription's datastore-xpath-filter against the libyang context and warn if it does not resolve to a schema node, or resolves but isn't in libyang's canonical (SchemaPathFormat:: DATA) form. Diagnostic only, never mutates the target. Move xpath_diff and strip_xpath_predicates into netconf-proto's xpath module so they're reusable and directly testable.
rodonile
force-pushed
the
xpath-normalization
branch
from
August 25, 2026 16:12
c4de624 to
6a66ed9
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new normalization logic currently treats // (descendant axis) as acceptable input (instead of bailing as documented), and strip_xpath_predicates can silently truncate malformed inputs, leading to incorrect normalization/diagnostics.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 2
- Review effort level: Lite
Comment on lines
+417
to
+420
| // Empty segment: leading '/' (absolute) or '//' (descendant). | ||
| if seg.is_empty() { | ||
| continue; | ||
| } |
Comment on lines
+193
to
+216
| pub fn strip_xpath_predicates(path: &str) -> String { | ||
| let mut out = String::with_capacity(path.len()); | ||
| let mut depth: u32 = 0; | ||
| let mut in_single = false; | ||
| let mut in_double = false; | ||
| for c in path.chars() { | ||
| if depth == 0 { | ||
| if c == '[' { | ||
| depth = 1; | ||
| } else { | ||
| out.push(c); | ||
| } | ||
| } else { | ||
| match c { | ||
| '\'' if !in_double => in_single = !in_single, | ||
| '"' if !in_single => in_double = !in_double, | ||
| '[' if !in_single && !in_double => depth += 1, | ||
| ']' if !in_single && !in_double => depth -= 1, | ||
| _ => {} | ||
| } | ||
| } | ||
| } | ||
| out | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR depends on network-analytics#43.
Summary
Normalizes
datastore-xpath-filtertargets — from both NETCONF/XMLsubscription fetches and JSON-encoded
SubscriptionStarted/SubscriptionModifiednotifications — to RFC 8641's module-name-qualified,prefix-on-change form, and adds a diagnostic that warns when a
target xpath doesn't resolve against the loaded schema or isn't in libyang's
canonical form.
Motivation
Different publishers/transports encode the same xpath target
differently: some use declared
xmlnsprefixes, some use baremodule-name prefixes, some repeat the prefix on every step instead
of only on module change. This caused issues to non-YANG-aware
post processing engines that are relying on xpath matching
for filtering messages.
Changes
new
crates/netconf-proto/src/xpath.rsmodule.DatastoreXPathFilter::normalize_path, the canonicalizationengine (bails safely to the original path on anything unsupported).
declared prefixes via the router's YANG library) and JSON-encoded
SubscriptionStarted/Modifiedtargets.check_xpath_target_resolves, a diagnostic that warns when atarget xpath doesn't resolve against the loaded schema or isn't in
libyang's canonical form.