Allow escaped quotes in "reason" field

This commit is contained in:
Shy 2024-08-28 13:32:58 +02:00
parent a3e18ebec8
commit 6433e6f14e

4
c4mate
View file

@ -12,6 +12,7 @@ HOST = "http://mate.labor.koeln.ccc.de"
local function utf8_decode(str) local function utf8_decode(str)
-- Replace JSON Unicode escape sequences with chars. -- Replace JSON Unicode escape sequences with chars.
if str == nil then return "" end if str == nil then return "" end
str = string.gsub(str, "\\\"", "\"")
return string.gsub(str, "\\u(%x%x%x%x)", return string.gsub(str, "\\u(%x%x%x%x)",
function (s) return utf8.char(tonumber(s, 16)) end) function (s) return utf8.char(tonumber(s, 16)) end)
end end
@ -101,6 +102,7 @@ function MatePad:parse_log(size)
-- Then extract and print oldbalance, newbalance, parameter and method. -- Then extract and print oldbalance, newbalance, parameter and method.
-- Depending on method, print either reason or item_name. If any extraction -- Depending on method, print either reason or item_name. If any extraction
-- fails we fail with exit code 1. -- fails we fail with exit code 1.
-- Note: we allow quoted quotation marks in "reason".
pipe = io.popen(string.format([=[ pipe = io.popen(string.format([=[
curl %s --header "Accept: application/json" "%s/api/user/%s/log?type=json" | \ curl %s --header "Accept: application/json" "%s/api/user/%s/log?type=json" | \
sed -n --sandbox ' sed -n --sandbox '
@ -128,7 +130,7 @@ sed -n '
T fail T fail
/set_balance\|transfer/{ /set_balance\|transfer/{
g g
s/.*"reason" *: *\(null\|"\([^"]*\)"\).*/\2/p s/.*"reason" *: *\(null\|"\(\([^"]\|\\"\)*[^\\]\)"\).*/\2/p
T fail T fail
b b
} }