From d4c145179420e6de0d2189059ea988072a7e7e45 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 10 Dec 2021 22:48:45 +0100 Subject: util.format: Escape invalid UTF-8 by passing trough serialization Should prevent invalid UTF-8 from making it into the logs, which can cause trouble with terminals or log viewers or other tools, such as when grep determines that log files are binary. --- spec/util_format_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec') diff --git a/spec/util_format_spec.lua b/spec/util_format_spec.lua index d58c25aa..8d6ba8ad 100644 --- a/spec/util_format_spec.lua +++ b/spec/util_format_spec.lua @@ -20,5 +20,9 @@ describe("util.format", function() assert.equal("␁", format("%s", "\1")); end); + it("escapes invalid UTF-8", function () + assert.equal("\"Hello w\\195rld\"", format("%s", "Hello w\195rld")); + end); + end); end); -- cgit v1.2.3