aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_format_spec.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2022-01-27 21:14:22 +0100
committerKim Alvefur <zash@zash.se>2022-01-27 21:14:22 +0100
commitc551d3d8dd756816b550dadb9e226c2d3ea6f334 (patch)
treeab0d9de069e9388a4592635c9df40b79670cd72b /spec/util_format_spec.lua
parentd607d2898fc63f08c4143efc07b8eff7bb2e42a4 (diff)
downloadprosody-c551d3d8dd756816b550dadb9e226c2d3ea6f334.tar.gz
prosody-c551d3d8dd756816b550dadb9e226c2d3ea6f334.zip
util.format: Skip control code escaping when doing full serialization
Fixes that a multi-line string ended up "like\ \9this" instead of "like\nthis" as can be demonstrated by somehow initiating a connection to a HTTP server.
Diffstat (limited to 'spec/util_format_spec.lua')
-rw-r--r--spec/util_format_spec.lua9
1 files changed, 7 insertions, 2 deletions
diff --git a/spec/util_format_spec.lua b/spec/util_format_spec.lua
index 184b8bd8..cb473b47 100644
--- a/spec/util_format_spec.lua
+++ b/spec/util_format_spec.lua
@@ -37,6 +37,11 @@ describe("util.format", function()
end)
end
+ it("escapes multi-line strings", function ()
+ assert.equal("Hello\n\tWorld", format("%s", "Hello\nWorld"))
+ assert.equal("\"Hello\\nWorld\"", format("%q", "Hello\nWorld"))
+ end)
+
-- Tests generated with loops!
describe("nil", function ()
describe("to %c", function ()
@@ -561,8 +566,8 @@ describe("util.format", function()
describe("to %q", function ()
it("works", function ()
assert.equal("\"hello\"", format("%q", "hello"))
- assert.equal("\"foo \226\144\129\226\144\130\226\144\131 bar\"", format("%q", "foo \001\002\003 bar"))
- assert.equal("\"nödåtgärd\"", format("%q", "n\195\182d\195\165tg\195\164rd"))
+ assert.equal("\"foo \\001\\002\\003 bar\"", format("%q", "foo \001\002\003 bar"))
+ assert.equal("\"n\\195\\182d\\195\\165tg\\195\\164rd\"", format("%q", "n\195\182d\195\165tg\195\164rd"))
assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%q", "n\195\182d\195\165tg\195"))
end);
end);