Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/schema_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ lysc_update_path(struct lysc_ctx *ctx, const struct lys_module *parent_module, c
if (ctx->path[ctx->path_used - 1] == '}') {
do {
--ctx->path_used;
if (ctx->path[ctx->path_used] == '\'') {
/* skip quoted string */
quot = quot ? 0 : ctx->path[ctx->path_used];
if ((ctx->path[ctx->path_used] == '\'') || (ctx->path[ctx->path_used] == '"')) {
/* skip quoted string, the other quote character may be a part of it */
if (!quot) {
quot = ctx->path[ctx->path_used];
} else if (quot == ctx->path[ctx->path_used]) {
quot = 0;
}
}
} while (quot || ((ctx->path[ctx->path_used] != '=') && (ctx->path[ctx->path_used] != '{')));
} while (ctx->path_used && (quot || ((ctx->path[ctx->path_used] != '=') &&
(ctx->path[ctx->path_used] != '{'))));
if (ctx->path[ctx->path_used] == '=') {
ctx->path[ctx->path_used++] = '}';
} else {
Expand All @@ -75,7 +80,7 @@ lysc_update_path(struct lysc_ctx *ctx, const struct lys_module *parent_module, c
}
} else {
remove_nodelevel:
for ( ; ctx->path[ctx->path_used] != '/'; --ctx->path_used) {}
for ( ; ctx->path_used && (ctx->path[ctx->path_used] != '/'); --ctx->path_used) {}
if (!ctx->path_used) {
free(ctx->path);
ctx->path = NULL;
Expand All @@ -89,7 +94,7 @@ lysc_update_path(struct lysc_ctx *ctx, const struct lys_module *parent_module, c
}
} else {
if (!parent_module && ctx->path_used && (ctx->path[ctx->path_used - 1] == '}') &&
(ctx->path[ctx->path_used - 2] != '\'')) {
(ctx->path[ctx->path_used - 2] != '\'') && (ctx->path[ctx->path_used - 2] != '"')) {
/* extension of the special tag */
spec = 1;
--ctx->path_used;
Expand All @@ -104,7 +109,9 @@ lysc_update_path(struct lysc_ctx *ctx, const struct lys_module *parent_module, c
ly_append_str(&ctx->path, &ctx->path_size, &ctx->path_used, "/%s:%s", ctx->cur_mod->name, name);
}
} else {
ly_append_str(&ctx->path, &ctx->path_size, &ctx->path_used, "='%s'}", name);
/* use the quote character that is not in the value */
quot = strchr(name, '\'') ? '"' : '\'';
ly_append_str(&ctx->path, &ctx->path_size, &ctx->path_used, "=%c%s%c}", quot, name, quot);
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/utests/schema/test_tree_schema_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3121,6 +3121,12 @@ test_augment(void **state)
"augment /x/ {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"/x/\" - unexpected end of expression.", "/aa:{augment='/x/'}", 0);

/* a quote in the target must not break removing the augment from the log path */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aq {namespace urn:aq;prefix aq; container c {leaf a {type string;}}"
"augment \"/c'x\" {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"/c'x\" - invalid syntax.", "/aq:{augment=\"/c'x\"}", 0);
CHECK_LOG_CTX("Unterminated string delimited with ' ('x).", "/aq:{augment=\"/c'x\"}", 0);

assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
"augment /x {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Augment target node \"/x\" from module \"aa\" was not found.", "/aa:{augment='/x'}", 0);
Expand Down