From ea29526f5414e2f8d638824a596c9bc6a82f8281 Mon Sep 17 00:00:00 2001 From: Shy Date: Wed, 28 Aug 2024 13:49:27 +0200 Subject: [PATCH 1/2] Allow escaped quotation marks in item_name --- c4mate | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c4mate b/c4mate index 8632ef1..86d521c 100755 --- a/c4mate +++ b/c4mate @@ -102,7 +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". + -- Note: we allow escaped quotation marks in "reason" and "item_name". pipe = io.popen(string.format([=[ curl %s --header "Accept: application/json" "%s/api/user/%s/log?type=json" | \ sed -n --sandbox ' @@ -135,7 +135,7 @@ sed -n ' b } g - s/.*"item_name" *: *\(null\|"\([^"]*\)"\).*/\2/p + s/.*"item_name" *: *\(null\|"\(\([^"]\|\\"\)*[^\\]\)"\).*/\2/p T fail b :fail From e5b2b4e016ec2c278ea281857f2e6023922db538 Mon Sep 17 00:00:00 2001 From: Shy Date: Wed, 28 Aug 2024 14:41:06 +0200 Subject: [PATCH 2/2] Parse -u prior to -h --- c4mate | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/c4mate b/c4mate index 86d521c..3bcb0d1 100755 --- a/c4mate +++ b/c4mate @@ -305,6 +305,14 @@ function MatePad:give(amount, recipient, reason) }) end + +-- Parse -u flag (which may be given multiple times). +while arg[1] == "-u" do + table.remove(arg, 1) + USER = arg[1] + table.remove(arg, 1) +end + -- Process help and username options. if arg[1] == "-h" or arg[1] == "--help" then @@ -326,13 +334,6 @@ Give credits: os.exit(0) end --- Parse -u flag (which may be given multiple times). -while arg[1] == "-u" do - table.remove(arg, 1) - USER = arg[1] - table.remove(arg, 1) -end - -- Set up username. if USER == nil then USER = os.getenv("USER")