From 6433e6f14ece6f3ab27f8c059df193bad43509a1 Mon Sep 17 00:00:00 2001 From: Shy Date: Wed, 28 Aug 2024 13:32:58 +0200 Subject: [PATCH] Allow escaped quotes in "reason" field --- c4mate | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/c4mate b/c4mate index 5439b19..8845b30 100755 --- a/c4mate +++ b/c4mate @@ -12,6 +12,7 @@ HOST = "http://mate.labor.koeln.ccc.de" local function utf8_decode(str) -- Replace JSON Unicode escape sequences with chars. if str == nil then return "" end + str = string.gsub(str, "\\\"", "\"") return string.gsub(str, "\\u(%x%x%x%x)", function (s) return utf8.char(tonumber(s, 16)) end) end @@ -101,6 +102,7 @@ function MatePad:parse_log(size) -- Then extract and print oldbalance, newbalance, parameter and method. -- Depending on method, print either reason or item_name. If any extraction -- fails we fail with exit code 1. + -- Note: we allow quoted quotation marks in "reason". pipe = io.popen(string.format([=[ curl %s --header "Accept: application/json" "%s/api/user/%s/log?type=json" | \ sed -n --sandbox ' @@ -128,7 +130,7 @@ sed -n ' T fail /set_balance\|transfer/{ g - s/.*"reason" *: *\(null\|"\([^"]*\)"\).*/\2/p + s/.*"reason" *: *\(null\|"\(\([^"]\|\\"\)*[^\\]\)"\).*/\2/p T fail b }