fix(strutil): encode default trim characters as runes (#369)

This commit is contained in:
Yusuf Efe authored and GitHub committed 2026-10-23 18:14:58 +08:00
1 parent 33a7e5bf6d
commit 145959ee62
2 files changed
+7 -1

No files matched your search

+1 -1
View File
@@ -519,7 +519,7 @@ func SplitAndTrim(str, delimiter string, characterMask ...string) []string {
var ( var (
// DefaultTrimChars are the characters which are stripped by Trim* functions in default. // DefaultTrimChars are the characters which are stripped by Trim* functions in default.
DefaultTrimChars = string([]byte{ DefaultTrimChars = string([]rune{
'\t', // Tab. '\t', // Tab.
'\v', // Vertical tab. '\v', // Vertical tab.
'\n', // New line (line feed). '\n', // New line (line feed).
+6
View File
@@ -686,6 +686,12 @@ func TestReplaceWithMap(t *testing.T) {
func TestTrim(t *testing.T) { func TestTrim(t *testing.T) {
t.Parallel() 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") assert := internal.NewAssert(t, "TestTrim")