]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
yparser: fix invalid error line number for lines with leading tabulator
authorDaniel Salzman <daniel.salzman@nic.cz>
Sun, 23 Jun 2019 19:48:02 +0000 (21:48 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Sun, 23 Jun 2019 19:54:30 +0000 (21:54 +0200)
src/libknot/yparser/ypbody.c
src/libknot/yparser/ypbody.rl
tests/libknot/test_yparser.c

index 73b77f52fbc9e0b78c093b449d99ba11359e6ea2..b1d0a721efa9bbf1a5fc0c9f3188d7281d21e320 100644 (file)
@@ -1,5 +1,5 @@
 
-/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     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[] = {
index b8f1a08fd0ca3bd76901b149ce5c3293592fb1ae..360f2af840f06309919194ca4c34da08f558ef46 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     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 = '#';
index ac7dbfc4dc2b60d8562e89bbca328b2357df3fbf..3662cdeb14390db2dabc1bc284bccb26080b0d94 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     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);