Comparison

spec/util_format_spec.lua @ 12220:25b853e64d83

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.
author Kim Alvefur <zash@zash.se>
date Thu, 27 Jan 2022 21:14:22 +0100
parent 12039:e0a8c5b1ab4f
child 12571:c4337ff4f1c4
comparison
equal deleted inserted replaced
12219:0a44def211fa 12220:25b853e64d83
35 it("does something with %p formats", function () 35 it("does something with %p formats", function ()
36 assert.string(format("%p", {})); 36 assert.string(format("%p", {}));
37 end) 37 end)
38 end 38 end
39 39
40 it("escapes multi-line strings", function ()
41 assert.equal("Hello\n\tWorld", format("%s", "Hello\nWorld"))
42 assert.equal("\"Hello\\nWorld\"", format("%q", "Hello\nWorld"))
43 end)
44
40 -- Tests generated with loops! 45 -- Tests generated with loops!
41 describe("nil", function () 46 describe("nil", function ()
42 describe("to %c", function () 47 describe("to %c", function ()
43 it("works", function () 48 it("works", function ()
44 assert.equal("(nil)", format("%c", nil)) 49 assert.equal("(nil)", format("%c", nil))
559 end); 564 end);
560 565
561 describe("to %q", function () 566 describe("to %q", function ()
562 it("works", function () 567 it("works", function ()
563 assert.equal("\"hello\"", format("%q", "hello")) 568 assert.equal("\"hello\"", format("%q", "hello"))
564 assert.equal("\"foo \226\144\129\226\144\130\226\144\131 bar\"", format("%q", "foo \001\002\003 bar")) 569 assert.equal("\"foo \\001\\002\\003 bar\"", format("%q", "foo \001\002\003 bar"))
565 assert.equal("\"nödåtgärd\"", format("%q", "n\195\182d\195\165tg\195\164rd")) 570 assert.equal("\"n\\195\\182d\\195\\165tg\\195\\164rd\"", format("%q", "n\195\182d\195\165tg\195\164rd"))
566 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%q", "n\195\182d\195\165tg\195")) 571 assert.equal("\"n\\195\\182d\\195\\165tg\\195\"", format("%q", "n\195\182d\195\165tg\195"))
567 end); 572 end);
568 end); 573 end);
569 574
570 describe("to %s", function () 575 describe("to %s", function ()