Skip to content

Commit 7f0874b

Browse files
committed
Repeat pattern fix : don't raise if multiple parsers without name + add test
1 parent 530b7f2 commit 7f0874b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3029,12 +3029,12 @@ chkNoDupeDotInParserDefs(ln_ctx ctx, struct json_object *parsers)
30293029
if(json_object_get_type(parsers) == json_type_array) {
30303030
const int maxparsers = json_object_array_length(parsers);
30313031
for(int i = 0 ; i < maxparsers ; ++i) {
3032-
++nParsers;
30333032
struct json_object *const parser
30343033
= json_object_array_get_idx(parsers, i);
30353034
struct json_object *fname;
30363035
json_object_object_get_ex(parser, "name", &fname);
30373036
if(fname != NULL) {
3037+
++nParsers;
30383038
if(!strcmp(json_object_get_string(fname), "."))
30393039
++nDots;
30403040
}

tests/repeat_name_dot.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# added 2023-02-14 by Kevin Guillemot
3+
# This file is part of the liblognorm project, released under ASL 2.0
4+
5+
. $srcdir/exec.sh
6+
7+
test_def $0 "Repeat with one parser named dot"
8+
add_rule 'version=2'
9+
add_rule 'rule=:a %{"name":"numbers", "type":"repeat",
10+
"parser":[
11+
{"type":"number"},
12+
{"type":"literal", "text":":"},
13+
{"name":".", "type":"number"}
14+
],
15+
"while":[
16+
{"type":"literal", "text":", "}
17+
]
18+
}% b %w:word%
19+
'
20+
execute 'a 1:2, 3:4, 5:6, 7:8 b test'
21+
assert_output_json_eq '{ "w": "test", "numbers": [ "2", "4", "6", "8" ] }'
22+
23+
cleanup_tmp_files

0 commit comments

Comments
 (0)