diff --git a/src/path.c b/src/path.c index ec0c5e3a7..d3cea0d7a 100644 --- a/src/path.c +++ b/src/path.c @@ -343,6 +343,13 @@ ly_path_parse(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const path_len = strlen(str_path); } + /* check if path begins with '/' if expected to and fail early if not */ + if ((begin == LY_PATH_BEGIN_ABSOLUTE) && (str_path[0] != '/')) { + LOGVAL(ctx, LYVE_XPATH, "XPath \"%.*s\" was expected to be absolute.", (int)path_len, str_path); + ret = LY_EVALID; + goto error; + } + /* parse as a generic XPath expression, reparse is performed manually */ LY_CHECK_GOTO(ret = lyxp_expr_parse(ctx, str_path, path_len, 0, &exp), error); tok_idx = 0; diff --git a/tests/utests/types/instanceid.c b/tests/utests/types/instanceid.c index ce5a24e46..b690d4178 100644 --- a/tests/utests/types/instanceid.c +++ b/tests/utests/types/instanceid.c @@ -200,7 +200,7 @@ test_data_xml(void **state) TEST_ERROR_XML2("", "defs", "xmlns:m=\"urn:tests:mod\"", "l1", "[1]", LY_EVALID); - CHECK_LOG_CTX("Invalid instance-identifier \"[1]\" value - syntax error: Unexpected XPath token \"[\" (\"[1]\"), expected \"Operator(Path)\".", + CHECK_LOG_CTX("Invalid instance-identifier \"[1]\" value - syntax error: XPath \"[1]\" was expected to be absolute.", "/defs:l1", 1); TEST_ERROR_XML2("",