Skip to content

Commit 254579d

Browse files
committed
parser yang BUGFIX support \r newlines
Fixes #2376
1 parent cf0fdff commit 254579d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/parser_yang.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,11 @@ read_qstring(struct lysp_yang_ctx *ctx, enum yang_arg arg, char **word_p, char *
417417
break;
418418
case '\r':
419419
/* newline may be escaped */
420-
if ((ctx->in->current[1] != '\n') && strncmp(&ctx->in->current[1], "\\n", 2)) {
421-
LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, ctx->in->current[0]);
422-
return LY_EVALID;
423-
}
420+
if ((ctx->in->current[1] == '\n') || !strncmp(&ctx->in->current[1], "\\n", 2)) {
421+
/* skip this character, do not store it */
422+
++ctx->in->current;
423+
} /* else just store '\n' instead */
424424

425-
/* skip this character, do not store it */
426-
++ctx->in->current;
427425
/* fallthrough */
428426
case '\n':
429427
if (block_indent) {
@@ -437,9 +435,20 @@ read_qstring(struct lysp_yang_ctx *ctx, enum yang_arg arg, char **word_p, char *
437435
current_indent = 0;
438436
}
439437

438+
c = NULL;
439+
if (ctx->in->current[0] != '\n') {
440+
/* storing '\r' as '\n' */
441+
c = ctx->in->current;
442+
ctx->in->current = "\n";
443+
}
444+
440445
/* check and store character */
441446
LY_CHECK_RET(buf_store_char(ctx, arg, word_p, word_len, word_b, buf_len, need_buf, &prefix));
442447

448+
if (c) {
449+
ctx->in->current = c + 1;
450+
}
451+
443452
/* reset context indentation counter for possible string after this one */
444453
ctx->indent = 0;
445454
trailing_ws = 0;

0 commit comments

Comments
 (0)