mirror of
https://github.com/fiatjaf/nak.git
synced 2026-04-10 15:36:54 +02:00
fix potential double-yield() usage on reading lines from stdin.
This commit is contained in:
12
helpers.go
12
helpers.go
@@ -64,6 +64,7 @@ func getJsonsOrBlank() iter.Seq[string] {
|
||||
|
||||
var finalJsonErr error
|
||||
return func(yield func(string) bool) {
|
||||
stopped := false
|
||||
hasStdin := writeStdinLinesOrNothing(func(stdinLine string) bool {
|
||||
// we're look for an event, but it may be in multiple lines, so if json parsing fails
|
||||
// we'll try the next line until we're successful
|
||||
@@ -78,6 +79,7 @@ func getJsonsOrBlank() iter.Seq[string] {
|
||||
finalJsonErr = nil
|
||||
|
||||
if !yield(stdinEvent) {
|
||||
stopped = true
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -85,6 +87,10 @@ func getJsonsOrBlank() iter.Seq[string] {
|
||||
return true
|
||||
})
|
||||
|
||||
if stopped {
|
||||
return
|
||||
}
|
||||
|
||||
if !hasStdin {
|
||||
if !yield("{}") {
|
||||
return
|
||||
@@ -99,13 +105,19 @@ func getJsonsOrBlank() iter.Seq[string] {
|
||||
|
||||
func getStdinLinesOrBlank() iter.Seq[string] {
|
||||
return func(yield func(string) bool) {
|
||||
stopped := false
|
||||
hasStdin := writeStdinLinesOrNothing(func(stdinLine string) bool {
|
||||
if !yield(stdinLine) {
|
||||
stopped = true
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
if stopped {
|
||||
return
|
||||
}
|
||||
|
||||
if !hasStdin {
|
||||
if !yield("") {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user