File tree Expand file tree Collapse file tree 4 files changed +44
-5
lines changed
Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Original file line number Diff line number Diff line change 6565}
6666
6767func (self * StashLoader ) getUnfilteredStashEntries () []* models.StashEntry {
68- rawString , _ := self .cmd .New ("git stash list --pretty='%gs'" ).DontLog ().RunWithOutput ()
69- return slices .MapWithIndex (utils .SplitLines (rawString ), func (line string , index int ) * models.StashEntry {
68+ rawString , _ := self .cmd .New ("git stash list -z - -pretty='%gs'" ).DontLog ().RunWithOutput ()
69+ return slices .MapWithIndex (utils .SplitNul (rawString ), func (line string , index int ) * models.StashEntry {
7070 return self .stashEntryFromLine (line , index )
7171 })
7272}
Original file line number Diff line number Diff line change @@ -22,16 +22,16 @@ func TestGetStashEntries(t *testing.T) {
2222 "No stash entries found" ,
2323 "" ,
2424 oscommands .NewFakeRunner (t ).
25- Expect (`git stash list --pretty='%gs'` , "" , nil ),
25+ Expect (`git stash list -z - -pretty='%gs'` , "" , nil ),
2626 []* models.StashEntry {},
2727 },
2828 {
2929 "Several stash entries found" ,
3030 "" ,
3131 oscommands .NewFakeRunner (t ).
3232 Expect (
33- `git stash list --pretty='%gs'` ,
34- "WIP on add-pkg-commands-test: 55c6af2 increase parallel build\n WIP on master: bb86a3f update github template" ,
33+ `git stash list -z - -pretty='%gs'` ,
34+ "WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00 WIP on master: bb86a3f update github template\x00 " ,
3535 nil ,
3636 ),
3737 []* models.StashEntry {
Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ func SplitLines(multilineString string) []string {
1717 return lines
1818}
1919
20+ func SplitNul (str string ) []string {
21+ if str == "" {
22+ return make ([]string , 0 )
23+ }
24+ str = strings .TrimSuffix (str , "\x00 " )
25+ return strings .Split (str , "\x00 " )
26+ }
27+
2028// NormalizeLinefeeds - Removes all Windows and Mac style line feeds
2129func NormalizeLinefeeds (str string ) string {
2230 str = strings .Replace (str , "\r \n " , "\n " , - 1 )
Original file line number Diff line number Diff line change @@ -36,6 +36,37 @@ func TestSplitLines(t *testing.T) {
3636 }
3737}
3838
39+ func TestSplitNul (t * testing.T ) {
40+ type scenario struct {
41+ multilineString string
42+ expected []string
43+ }
44+
45+ scenarios := []scenario {
46+ {
47+ "" ,
48+ []string {},
49+ },
50+ {
51+ "\x00 " ,
52+ []string {
53+ "" ,
54+ },
55+ },
56+ {
57+ "hello world !\x00 hello universe !\x00 " ,
58+ []string {
59+ "hello world !" ,
60+ "hello universe !" ,
61+ },
62+ },
63+ }
64+
65+ for _ , s := range scenarios {
66+ assert .EqualValues (t , s .expected , SplitNul (s .multilineString ))
67+ }
68+ }
69+
3970// TestNormalizeLinefeeds is a function.
4071func TestNormalizeLinefeeds (t * testing.T ) {
4172 type scenario struct {
You can’t perform that action at this time.
0 commit comments