diff options
-rw-r--r-- | marigold.lua | 6 | ||||
-rwxr-xr-x | test.lua | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/marigold.lua b/marigold.lua index ac0e061..02c9bbe 100644 --- a/marigold.lua +++ b/marigold.lua @@ -121,5 +121,11 @@ marigold.html = function(tbl, indent_level) indent, close) end +marigold.percentDecode = function(str) + return string.gsub(str, "%%(%x%x)", function(digits) + return string.char(tonumber(digits, 16)) + end) +end + return marigold @@ -162,3 +162,10 @@ test("marigold.html correctly renders children", function() <p>p2</p> </div>]]) end) + + +test("marigold.percentDecode correctly decodes percent-encoded strings", function() + local str = '%20%21%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D' + assert(marigold.percentDecode(str) == " !#$%&'()*+,/:;=?@[]") + assert(marigold.percentDecode('%25+%2b') == '%++') +end) |