mirror of
https://github.com/fiatjaf/nak.git
synced 2026-10-05 23:28:23 +00:00
fix potential double-yield() usage on reading lines from stdin.
This commit is contained in:
+12
@@ -64,6 +64,7 @@ func getJsonsOrBlank() iter.Seq[string] {
|
|||||||
|
|
||||||
var finalJsonErr error
|
var finalJsonErr error
|
||||||
return func(yield func(string) bool) {
|
return func(yield func(string) bool) {
|
||||||
|
stopped := false
|
||||||
hasStdin := writeStdinLinesOrNothing(func(stdinLine string) bool {
|
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'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
|
// we'll try the next line until we're successful
|
||||||
@@ -78,6 +79,7 @@ func getJsonsOrBlank() iter.Seq[string] {
|
|||||||
finalJsonErr = nil
|
finalJsonErr = nil
|
||||||
|
|
||||||
if !yield(stdinEvent) {
|
if !yield(stdinEvent) {
|
||||||
|
stopped = true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +87,10 @@ func getJsonsOrBlank() iter.Seq[string] {
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if stopped {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !hasStdin {
|
if !hasStdin {
|
||||||
if !yield("{}") {
|
if !yield("{}") {
|
||||||
return
|
return
|
||||||
@@ -99,13 +105,19 @@ func getJsonsOrBlank() iter.Seq[string] {
|
|||||||
|
|
||||||
func getStdinLinesOrBlank() iter.Seq[string] {
|
func getStdinLinesOrBlank() iter.Seq[string] {
|
||||||
return func(yield func(string) bool) {
|
return func(yield func(string) bool) {
|
||||||
|
stopped := false
|
||||||
hasStdin := writeStdinLinesOrNothing(func(stdinLine string) bool {
|
hasStdin := writeStdinLinesOrNothing(func(stdinLine string) bool {
|
||||||
if !yield(stdinLine) {
|
if !yield(stdinLine) {
|
||||||
|
stopped = true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if stopped {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !hasStdin {
|
if !hasStdin {
|
||||||
if !yield("") {
|
if !yield("") {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user