mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(strutil): encode default trim characters as runes (#369)
This commit is contained in:
1 parent
33a7e5bf6d
commit
145959ee62
2 files changed
+7
-1
No files matched your search
+1
-1
@@ -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).
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user