summaryrefslogtreecommitdiffstats
path: root/pkg/utils
diff options
context:
space:
mode:
authorRyooooooga <eial5q265e5@gmail.com>2022-10-13 22:20:15 +0900
committerRyooooooga <eial5q265e5@gmail.com>2022-10-13 22:23:56 +0900
commita4239c7a37abad01e8c687fea5d6942e9da34c92 (patch)
tree921e9a9b77fe78fcb6ab63df867f9ada37e6b190 /pkg/utils
parentfc0b14edef63ae495ce55e843bdb82bacb7c58eb (diff)
fix: fix stash with empty message
Diffstat (limited to 'pkg/utils')
-rw-r--r--pkg/utils/lines.go8
-rw-r--r--pkg/utils/lines_test.go31
2 files changed, 39 insertions, 0 deletions
diff --git a/pkg/utils/lines.go b/pkg/utils/lines.go
index 47d33e939..662ba2f9b 100644
--- a/pkg/utils/lines.go
+++ b/pkg/utils/lines.go
@@ -17,6 +17,14 @@ func SplitLines(multilineString string) []string {
return lines
}
+func SplitNul(str string) []string {
+ if str == "" {
+ return make([]string, 0)
+ }
+ str = strings.TrimSuffix(str, "\x00")
+ return strings.Split(str, "\x00")
+}
+
// NormalizeLinefeeds - Removes all Windows and Mac style line feeds
func NormalizeLinefeeds(str string) string {
str = strings.Replace(str, "\r\n", "\n", -1)
diff --git a/pkg/utils/lines_test.go b/pkg/utils/lines_test.go
index 361f0a510..e7171022b 100644
--- a/pkg/utils/lines_test.go
+++ b/pkg/utils/lines_test.go
@@ -36,6 +36,37 @@ func TestSplitLines(t *testing.T) {
}
}
+func TestSplitNul(t *testing.T) {
+ type scenario struct {
+ multilineString string
+ expected []string
+ }
+
+ scenarios := []scenario{
+ {
+ "",
+ []string{},
+ },
+ {
+ "\x00",
+ []string{
+ "",
+ },
+ },
+ {
+ "hello world !\x00hello universe !\x00",
+ []string{
+ "hello world !",
+ "hello universe !",
+ },
+ },
+ }
+
+ for _, s := range scenarios {
+ assert.EqualValues(t, s.expected, SplitNul(s.multilineString))
+ }
+}
+
// TestNormalizeLinefeeds is a function.
func TestNormalizeLinefeeds(t *testing.T) {
type scenario struct {