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)
-- 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
}