Fix error with percent signs (%) in answer text
John Smith

John Smith commited on 2021-357 12:38:04
Showing 2 changed files, with 2 additions and 2 deletions.


Lua's `str:gsub(pattern, repl)` interprets `%` as a
sort of escape character in `repl`, so the presence of a `%`
in answer text would cause an error or undefined behaviour.
... ...
@@ -137,7 +137,7 @@ elseif action == "r" then
137 137
                 io.read("l")
138 138
                 io.write(string.format(
139 139
                     "%s\nDid you get it? ",
140
-                    pst:gsub("%%A", pr.ans)
140
+                    pst:gsub("%%A", pr.ans:gsub("%%", "%%%%"))
141 141
                 ))
142 142
                 local resp = io.read("l")
143 143
                 review.update(deck[ip[1]][ip[2]], st, isyes(resp))
... ...
@@ -35,7 +35,7 @@ end
35 35
     derive the `PromptText` used to create this `Prompt`
36 36
 ]]
37 37
 function Prompt:spt()
38
-    return self.text:gsub("%%A", "{" .. self.ans .. "}")
38
+    return self.text:gsub("%%A", "{" .. self.ans:gsub("%%", "%%%%") .. "}")
39 39
 end
40 40
 
41 41
 --[[
42 42