Skip to content

Commit

Permalink
Fixes mbj4668#518 - broken xpath check
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Björklund committed Nov 20, 2019
1 parent 4435dfe commit bf0bf09
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pyang/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,14 @@ def chk_xpath_path(ctx, mod, pos, initial, node, path):
else:
node1 = child
elif axis == 'parent' and nodetest == ('node_type', 'node'):
p = data_node_up(node)
if p is None:
if node == 'root':
err_add(ctx.errors, pos, 'XPATH_PATH_TOO_MANY_UP', ())
else:
node1 = p
p = data_node_up(node)
if p is None:
err_add(ctx.errors, pos, 'XPATH_PATH_TOO_MANY_UP', ())
else:
node1 = p
else:
# we can't validate the steps on other axis, but we can validate
# functions etc.
Expand Down
2 changes: 2 additions & 0 deletions test/test_issues/test_i518/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
pyang s.yang --print-error-code 2>&1 | diff s.expect -
1 change: 1 addition & 0 deletions test/test_issues/test_i518/s.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s.yang:12: error: XPATH_PATH_TOO_MANY_UP
19 changes: 19 additions & 0 deletions test/test_issues/test_i518/s.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
submodule s {
belongs-to a {
prefix a;
}

container test;

augment "/test" {
container x {
container test-1 {
leaf tcp-profile {
when "/../../test/protocol = 'test'";
type string;
}
}
}
}
}

0 comments on commit bf0bf09

Please sign in to comment.