aboutsummaryrefslogtreecommitdiffstats
path: root/main/liblognorm/parse-name-value-quoting-support.patch
blob: 3541f8008ff6a4c44a260b376a398703dfcf03ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
From 69392daac575cc29f9f3bf8f7369fae52f3fadf0 Mon Sep 17 00:00:00 2001
From: Benoit DOLEZ <bdolez@pom-monitoring.com>
Date: Thu, 15 Dec 2016 00:16:27 +0100
Subject: [PATCH] parseNameValue: fix no quoting support

Function description announce support of quoted variable :
- name=value
- name="value"
- name='value'

... but there is nothing in the code to really support quoted string.
I had small fixes to support it.

My tests :
$ cat > test.txt <<EOF
a=
a=123
a=123
a='123'
a="123"
a=123 b=456
a=123 b="456"
a=123 b="456" c=
a=123 b="456'789" c=
a=123 b="456 789" c=
a=123 b="456 789' c=
a=123 b=456 789 c=
EOF

$ cat > test.rb << EOF
version=2
rule=test-ok:%[
  {"type": "name-value-list"}
  ]%
EOF

$ cat test.txt | ./lognormalizer -r test.rb -T
{ "event.tags": [ "test-ok" ] }
{ "event.tags": [ "test-ok" ] }
{ "event.tags": [ "test-ok" ] }
{ "event.tags": [ "test-ok" ] }
{ "event.tags": [ "test-ok" ] }
{ "event.tags": [ "test-ok" ] }
{ "event.tags": [ "test-ok" ] }
{ "event.tags": [ "test-ok" ] }
{ "event.tags": [ "test-ok" ] }
{ "event.tags": [ "test-ok" ] }
{ "originalmsg": "a=123 b=\"456 789' c= ", "unparsed-data": "a=123 b=\"456 789' c= " }
{ "originalmsg": "a=123 b=456 789 c= ", "unparsed-data": "a=123 b=456 789 c= " }
---
 src/parser.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Patch-Source: https://github.com/rsyslog/liblognorm/pull/234

diff --git a/src/parser.c b/src/parser.c
index 7068362..74111f6 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1967,11 +1967,23 @@ parseNameValue(npb_t *const npb,
 	const size_t lenName = i - iName;
 	++i; /* skip '=' */
 
+	char quoting = npb->str[i]; // end of string
+	if (i < npb->strLen && (quoting == '"' || quoting == '\''))
+		++i;
+	else
+		quoting = 0; // str[i] can't be null, is a good default value
+
 	const size_t iVal = i;
-	while(i < npb->strLen && !isspace(npb->str[i]))
+	while(i < npb->strLen &&
+	     ((quoting && npb->str[i] != quoting) || (!quoting && !isspace(npb->str[i]))))
 		++i;
 	const size_t lenVal = i - iVal;
 
+	if (i < npb->strLen && npb->str[i] == quoting)
+		++i;
+	else if (quoting)
+		goto done;
+
 	/* parsing OK */
 	*offs = i;
 	r = 0;