Skip to content

Normalise import-alias prefixes in 'when' xpath expressions #240

@steiler

Description

@steiler

Background

YANG when statements contain an xpath expression that may include quoted string literals of the form 'prefix:identity-value'. When a module imports an identity module under a local alias that differs from the imported module's declared prefix, the raw xpath stored at schema compile time contains the local alias rather than the declared prefix.

This causes the xpath evaluator to fail to match identity values — the node is incorrectly treated as non-existent even for valid config.

This is the same root cause as the must statement prefix mismatch (already fixed for must via normalizeXPathLiterals in pkg/schema/leaf.go).

What needs to happen

Wherever the schema-server serialises a when xpath string into the proto, apply the same literal-prefix rewrite:

  • Scan quoted string literals ('...' and "...") in the xpath
  • For each 'alias:name' literal: look up alias in the entry's module import table via yang.FindModuleByPrefix
  • If found and alias != importedModule.GetPrefix(): rewrite to 'declaredPrefix:name'
  • Otherwise leave unchanged

normalizeXPathLiterals(xpath string, e *yang.Entry) in pkg/schema/leaf.go already implements this logic and is directly reusable — this is purely a call-site addition wherever e.When.Name is consumed.

Notes

  • when is simpler than must: single xpath string, no sub-statements (RFC 7950 §7.21.5)
  • Unlike must, when lives on yang.Entry.When.Name directly (not in e.Extra)
  • Testdata from the must fix (pkg/schema/testdata/must-alias/) can be extended with when statements
  • Idempotent and unknown-prefix cases must remain unchanged (same invariants as must)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions