From: Philipp Gesang Date: Thu, 7 Feb 2019 13:45:40 +0000 (+0100) Subject: handle data escaping properly in cnf vars X-Git-Tag: v1.4~12^2~3 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=5afd18a722cb939ed3fb5472ceda496e77fad7ac;p=pyi2ncommon handle data escaping properly in cnf vars libcnffile has an additional step that strips escaping from var data so this: 42 MY_VAR,0: "foo\"bar\"baz" is actually a valid CNF_VAR with a data member equals ``foo"bar"baz''. Till now, cnfvar.py would reject such a line because of the stricter matching. Since escaped strings are ubiquitous in JSON encoded data, this must be handled properly. (Ironically this is not an issue with the JSON interface due to the builtin string escaping rules of the format.) Imitate the behavior of libcnffile so properly escaped double quotes don't terminate the string matching. Lucky for us we can get away with extending the line regex with an alternating pattern in a non-matching group ``(?:...''. --- diff --git a/src/cnfvar.py b/src/cnfvar.py index 833a606..1b6b5bb 100644 --- a/src/cnfvar.py +++ b/src/cnfvar.py @@ -409,7 +409,10 @@ base_line_pattern = re.compile(b""" \s* # optional spaces : # delimiter \s* # optional spaces - \"([^\"]*)\" # quoted string (data) + \"( # quoted string (data) + (?: \\\" # (of escaped dquote + |[^\"])* # or anything not a + )\" # literal quote) \s* # optional spaces ( # bgroup \# # comment leader