From 6abc29a77519828ea2d2ca10434510f88716d67b Mon Sep 17 00:00:00 2001 From: Pedro Capelastegui Date: Mon, 28 Sep 2026 15:13:29 +0200 Subject: [PATCH] parser yang BUGFIX comments before string concatenation RFC 7950 sec. 6.1.3 allows comments between the quoted strings and the '+' character, not only after it. --- src/parser_yang.c | 14 ++++++++++++ tests/utests/schema/test_yang.c | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/parser_yang.c b/src/parser_yang.c index dee27b994..51abf66d5 100644 --- a/src/parser_yang.c +++ b/src/parser_yang.c @@ -539,6 +539,20 @@ read_qstring(struct lysp_yang_ctx *ctx, enum yang_arg arg, char **word_p, char * case '\t': /* just skip */ break; + case '/': + if (ctx->in->current[1] == '/') { + /* one-line comment */ + MOVE_INPUT(ctx, 2); + LY_CHECK_RET(skip_comment(ctx, 1)); + continue; + } else if (ctx->in->current[1] == '*') { + /* block comment */ + MOVE_INPUT(ctx, 2); + LY_CHECK_RET(skip_comment(ctx, 2)); + continue; + } + /* not a comment after all */ + /* fallthrough */ default: /* string is finished */ goto string_end; diff --git a/tests/utests/schema/test_yang.c b/tests/utests/schema/test_yang.c index d30251470..7ce36cdb5 100644 --- a/tests/utests/schema/test_yang.c +++ b/tests/utests/schema/test_yang.c @@ -205,6 +205,44 @@ test_arg(void **state) assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, &mod)); CHECK_LOG_CTX("Parsing module \"test13\" failed.", NULL, 0); CHECK_LOG_CTX("Both string parts divided by '+' must be quoted.", NULL, 5); + + /* comments between the quoted strings and '+' (RFC 7950 sec. 6.1.3.) */ + schema = "module test14 {\n" + " namespace urn:test14;\n" + " prefix t;\n" + " description \"hel\" /* comment */ + \'lo\';\n" + "}"; + assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, &mod)); + assert_string_equal("hello", mod->dsc); + + schema = "module test15 {\n" + " namespace urn:test15;\n" + " prefix t;\n" + " description \'hel\' // comment\n" + " + \"lo\";\n" + "}"; + assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, &mod)); + assert_string_equal("hello", mod->dsc); + + schema = "module test16 {\n" + " namespace urn:test16;\n" + " prefix t;\n" + " description \"h\"/* a */+/* b */\"el\" // c\n" + " /* d */ + // e\n" + " \'lo\' /* f */;\n" + "}"; + assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, &mod)); + assert_string_equal("hello", mod->dsc); + + schema = "module test17 {\n" + " namespace urn:test17;\n" + " prefix t;\n" + " description \"hel\" /* multi\n" + " line */ + lo;\n" + "}"; + assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, schema, LYS_IN_YANG, &mod)); + CHECK_LOG_CTX("Parsing module \"test17\" failed.", NULL, 0); + CHECK_LOG_CTX("Both string parts divided by '+' must be quoted.", NULL, 5); } #define TEST_STMS_SUCCESS(CTX, MOD_NAME, STMT_TEXT) \