mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-04-30 08:38:20 +02:00
84 lines
2.1 KiB
Diff
84 lines
2.1 KiB
Diff
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;
|