From bace4732e1cc44d6448a374aae2f78e454ff8048 Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Fri, 27 Mar 2026 16:42:28 +0800 Subject: [PATCH] Fix Logger.Utils.truncate_n UTF-8 range for two-byte code points Two-byte UTF-8 sequences start at U+0080 (128), not U+007F (127). The previous guard `127..0x07FF` overlapped the single-byte clause and could misclassify U+007F if clause order changed. Add regression tests for U+007F/U+0080 byte boundaries. --- lib/logger/lib/logger/utils.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logger/lib/logger/utils.ex b/lib/logger/lib/logger/utils.ex index 302e4829e8c..f355fa2ff47 100644 --- a/lib/logger/lib/logger/utils.ex +++ b/lib/logger/lib/logger/utils.ex @@ -228,7 +228,7 @@ defmodule Logger.Utils do end def truncate_n(int, n) when int in 0..127, do: {int, n - 1} - def truncate_n(int, n) when int in 127..0x07FF, do: {int, n - 2} + def truncate_n(int, n) when int in 128..0x07FF, do: {int, n - 2} def truncate_n(int, n) when int in 0x800..0xFFFF, do: {int, n - 3} def truncate_n(int, n) when int >= 0x10000 and is_integer(int), do: {int, n - 4}