From 145959ee62bda533768dfbc877761f48ab6b80a1 Mon Sep 17 00:00:00 2001 From: Yusuf Efe <120668197+yuefdev@users.noreply.github.com> Date: Fri, 23 Oct 2026 13:14:58 +0300 Subject: [PATCH] fix(strutil): encode default trim characters as runes (#369) --- strutil/string.go | 2 +- strutil/string_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/strutil/string.go b/strutil/string.go index 630f01e..29fac8b 100644 --- a/strutil/string.go +++ b/strutil/string.go @@ -519,7 +519,7 @@ func SplitAndTrim(str, delimiter string, characterMask ...string) []string { var ( // DefaultTrimChars are the characters which are stripped by Trim* functions in default. - DefaultTrimChars = string([]byte{ + DefaultTrimChars = string([]rune{ '\t', // Tab. '\v', // Vertical tab. '\n', // New line (line feed). diff --git a/strutil/string_test.go b/strutil/string_test.go index bb48a11..b95598d 100644 --- a/strutil/string_test.go +++ b/strutil/string_test.go @@ -686,6 +686,12 @@ func TestReplaceWithMap(t *testing.T) { func TestTrim(t *testing.T) { t.Parallel() + if got := Trim("\u0085\u00a0value\u00a0\u0085"); got != "value" { + t.Errorf("Trim Unicode whitespace = %q, want value", got) + } + if got := Trim("\ufffdvalue\ufffd"); got != "\ufffdvalue\ufffd" { + t.Errorf("Trim removed replacement characters: %q", got) + } assert := internal.NewAssert(t, "TestTrim")