Mercurial > prosody-hg
comparison spec/util_format_spec.lua @ 12032:3db09eb4c43b
util.format: Ensure sanitation of strings passed to wrong format
Ie. log("debug", "%d", "\1\2\3") should not result in garbage.
Also optimizing for the common case of ASCII string passed to %s and
early returns everywhere.
Returning nil from a gsub callback keeps the original substring.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 11 Dec 2021 13:30:34 +0100 |
| parents | 87bc26f23d9b |
| children | 161f8268c4b3 |
comparison
equal
deleted
inserted
replaced
| 12031:87bc26f23d9b | 12032:3db09eb4c43b |
|---|---|
| 16 assert.equal("[7.3786976294838e+19]", format("%d", 73786976294838206464)); | 16 assert.equal("[7.3786976294838e+19]", format("%d", 73786976294838206464)); |
| 17 end); | 17 end); |
| 18 | 18 |
| 19 it("escapes ascii control stuff", function () | 19 it("escapes ascii control stuff", function () |
| 20 assert.equal("␁", format("%s", "\1")); | 20 assert.equal("␁", format("%s", "\1")); |
| 21 assert.equal("[␁]", format("%d", "\1")); | |
| 21 end); | 22 end); |
| 22 | 23 |
| 23 it("escapes invalid UTF-8", function () | 24 it("escapes invalid UTF-8", function () |
| 24 assert.equal("\"Hello w\\195rld\"", format("%s", "Hello w\195rld")); | 25 assert.equal("\"Hello w\\195rld\"", format("%s", "Hello w\195rld")); |
| 25 end); | 26 end); |
