Skip to content

Commit f00a4a7

Browse files
committed
fix potential double-yield() usage on reading lines from stdin.
1 parent d823ac5 commit f00a4a7

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

helpers.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func getJsonsOrBlank() iter.Seq[string] {
6464

6565
var finalJsonErr error
6666
return func(yield func(string) bool) {
67+
stopped := false
6768
hasStdin := writeStdinLinesOrNothing(func(stdinLine string) bool {
6869
// we're look for an event, but it may be in multiple lines, so if json parsing fails
6970
// we'll try the next line until we're successful
@@ -78,13 +79,18 @@ func getJsonsOrBlank() iter.Seq[string] {
7879
finalJsonErr = nil
7980

8081
if !yield(stdinEvent) {
82+
stopped = true
8183
return false
8284
}
8385

8486
curr.Reset()
8587
return true
8688
})
8789

90+
if stopped {
91+
return
92+
}
93+
8894
if !hasStdin {
8995
if !yield("{}") {
9096
return
@@ -99,13 +105,19 @@ func getJsonsOrBlank() iter.Seq[string] {
99105

100106
func getStdinLinesOrBlank() iter.Seq[string] {
101107
return func(yield func(string) bool) {
108+
stopped := false
102109
hasStdin := writeStdinLinesOrNothing(func(stdinLine string) bool {
103110
if !yield(stdinLine) {
111+
stopped = true
104112
return false
105113
}
106114
return true
107115
})
108116

117+
if stopped {
118+
return
119+
}
120+
109121
if !hasStdin {
110122
if !yield("") {
111123
return

0 commit comments

Comments
 (0)