From: Daniel Salzman Date: Sun, 23 Jun 2019 19:48:02 +0000 (+0200) Subject: yparser: fix invalid error line number for lines with leading tabulator X-Git-Tag: v2.9.0~244 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83de00c53ff62cdc16eaedb46896782d39fdde56;p=thirdparty%2Fknot-dns.git yparser: fix invalid error line number for lines with leading tabulator --- diff --git a/src/libknot/yparser/ypbody.c b/src/libknot/yparser/ypbody.c index 73b77f52fb..b1d0a721ef 100644 --- a/src/libknot/yparser/ypbody.c +++ b/src/libknot/yparser/ypbody.c @@ -1,5 +1,5 @@ -/* Copyright (C) 2018 CZ.NIC, z.s.p.o. +/* Copyright (C) 2019 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -30,14 +30,15 @@ static const char _yparser_actions[] = { 3, 1, 4, 1, 6, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 15, 2, 1, 0, 2, 1, 2, 2, - 2, 0, 2, 3, 4, 2, 5, 4, - 2, 6, 0, 2, 7, 8, 2, 12, - 13, 2, 14, 12, 3, 1, 2, 0, - 3, 1, 7, 8, 3, 1, 12, 13, - 3, 1, 14, 12, 3, 2, 7, 8, - 3, 2, 12, 13, 3, 2, 14, 12, - 4, 1, 2, 7, 8, 4, 1, 2, - 12, 13, 4, 1, 2, 14, 12 + 1, 15, 2, 2, 0, 2, 3, 4, + 2, 5, 4, 2, 6, 0, 2, 7, + 8, 2, 12, 13, 2, 14, 12, 3, + 1, 2, 0, 3, 1, 7, 8, 3, + 1, 12, 13, 3, 1, 14, 12, 3, + 2, 7, 8, 3, 2, 12, 13, 3, + 2, 14, 12, 4, 1, 2, 7, 8, + 4, 1, 2, 12, 13, 4, 1, 2, + 14, 12 }; static const unsigned char _yparser_key_offsets[] = { @@ -122,11 +123,11 @@ static const char _yparser_indicies[] = { 0, 41, 43, 45, 0, 52, 49, 0, 53, 21, 0, 54, 56, 55, 55, 55, 55, 55, 0, 1, 2, 3, 4, 5, - 57, 57, 57, 57, 57, 0, 58, 59, - 60, 61, 62, 63, 63, 63, 63, 63, - 0, 64, 65, 66, 67, 68, 69, 69, - 69, 69, 69, 0, 70, 71, 72, 73, - 74, 75, 75, 75, 75, 75, 0, 0 + 57, 57, 57, 57, 57, 0, 59, 60, + 61, 62, 63, 64, 64, 64, 64, 64, + 58, 65, 66, 67, 68, 69, 70, 70, + 70, 70, 70, 0, 71, 72, 73, 74, + 75, 76, 76, 76, 76, 76, 58, 0 }; static const char _yparser_trans_targs[] = { @@ -137,22 +138,22 @@ static const char _yparser_trans_targs[] = { 19, 14, 15, 18, 16, 14, 20, 24, 23, 21, 20, 19, 23, 22, 21, 22, 20, 24, 25, 26, 24, 9, 11, 28, - 12, 10, 30, 31, 1, 2, 3, 10, - 30, 31, 1, 2, 3, 10, 30, 31, - 1, 2, 3, 10 + 12, 10, 0, 30, 31, 1, 2, 3, + 10, 30, 31, 1, 2, 3, 10, 30, + 31, 1, 2, 3, 10 }; static const char _yparser_trans_actions[] = { - 23, 1, 0, 46, 0, 49, 43, 21, - 43, 19, 13, 19, 0, 0, 0, 34, - 7, 34, 40, 11, 11, 9, 9, 15, + 23, 1, 0, 49, 0, 52, 46, 21, + 46, 19, 13, 19, 0, 0, 0, 37, + 7, 37, 43, 11, 11, 9, 9, 15, 13, 15, 0, 0, 1, 0, 0, 0, - 0, 9, 0, 9, 0, 37, 34, 7, - 34, 11, 9, 11, 9, 11, 0, 0, - 37, 9, 0, 9, 37, 37, 17, 13, - 17, 43, 52, 28, 85, 28, 90, 80, - 31, 5, 72, 5, 76, 68, 25, 3, - 60, 3, 64, 56 + 0, 9, 0, 9, 0, 40, 37, 7, + 37, 11, 9, 11, 9, 11, 0, 0, + 40, 9, 0, 9, 40, 40, 17, 13, + 17, 46, 31, 55, 28, 88, 28, 93, + 83, 34, 5, 75, 5, 79, 71, 25, + 3, 63, 3, 67, 59 }; static const char _yparser_eof_actions[] = { diff --git a/src/libknot/yparser/ypbody.rl b/src/libknot/yparser/ypbody.rl index b8f1a08fd0..360f2af840 100644 --- a/src/libknot/yparser/ypbody.rl +++ b/src/libknot/yparser/ypbody.rl @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 CZ.NIC, z.s.p.o. +/* Copyright (C) 2019 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,7 +38,7 @@ parser->event = YP_ENULL; parser->processed = false; } - newline_char = '\n' >_newline_init %_newline | '\r'; + newline_char = '\n' >_newline_init %_newline %!_newline | '\r'; # Comment processing. comment_char = '#'; diff --git a/tests/libknot/test_yparser.c b/tests/libknot/test_yparser.c index ac7dbfc4dc..3662cdeb14 100644 --- a/tests/libknot/test_yparser.c +++ b/tests/libknot/test_yparser.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 CZ.NIC, z.s.p.o. +/* Copyright (C) 2019 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -81,6 +81,18 @@ const char *syntax_error3 = " a: b\n" " c: d\n"; +const char *tab_error1 = + "a:\n" + "b:\t\n"; + +const char *tab_error2 = + "a:\n" + "b: c\t\n"; + +const char *tab_error3 = + "a:\n" + "\t\n"; + const char *dname_ok = ".:\n" "dom-ain:\n" @@ -211,13 +223,27 @@ static void test_syntax_error(yp_parser_t *yp, const char *input) static int count = 1; int ret = yp_set_input_string(yp, input, strlen(input)); - is_int(KNOT_EOK, ret, "set error input string %i", count++); + is_int(KNOT_EOK, ret, "set syntax error input string %i", count++); ret = yp_parse(yp); is_int(KNOT_EOK, ret, "parse key0"); ret = yp_parse(yp); is_int(KNOT_EOK, ret, "parse key1"); ret = yp_parse(yp); is_int(KNOT_YP_EINVAL_INDENT, ret, "parse key1 - invalid indentation"); + is_int(yp->line_count, 3, "invalid indentation line"); +} + +static void test_tab_error(yp_parser_t *yp, const char *input) +{ + static int count = 1; + + int ret = yp_set_input_string(yp, input, strlen(input)); + is_int(KNOT_EOK, ret, "set tab error input string %i", count++); + ret = yp_parse(yp); + is_int(KNOT_EOK, ret, "parse key0"); + ret = yp_parse(yp); + is_int(KNOT_YP_ECHAR_TAB, ret, "invalid tabulator"); + is_int(yp->line_count, 2, "invalid tabulator line"); } static void test_dname(yp_parser_t *yp) @@ -271,6 +297,9 @@ int main(int argc, char *argv[]) test_syntax_error(&yp, syntax_error1); test_syntax_error(&yp, syntax_error2); test_syntax_error(&yp, syntax_error3); + test_tab_error(&yp, tab_error1); + test_tab_error(&yp, tab_error2); + test_tab_error(&yp, tab_error3); test_dname(&yp); test_quotes(&yp);