mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fixed EOF bug when processing empty files
This commit is contained in:
parent
171ca2e053
commit
a13617407e
@ -1,2 +0,0 @@
|
|||||||
# a: apple
|
|
||||||
# b: cat
|
|
@ -15,6 +15,12 @@ func readStream(filename string) (io.Reader, bool, error) {
|
|||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
seperatorBytes, err := reader.Peek(3)
|
seperatorBytes, err := reader.Peek(3)
|
||||||
|
|
||||||
|
if err == io.EOF {
|
||||||
|
// EOF are handled else where..
|
||||||
|
return reader, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
return reader, string(seperatorBytes) == "---", err
|
return reader, string(seperatorBytes) == "---", err
|
||||||
} else {
|
} else {
|
||||||
// ignore CWE-22 gosec issue - that's more targetted for http based apps that run in a public directory,
|
// ignore CWE-22 gosec issue - that's more targetted for http based apps that run in a public directory,
|
||||||
@ -25,7 +31,10 @@ func readStream(filename string) (io.Reader, bool, error) {
|
|||||||
}
|
}
|
||||||
seperatorBytes := make([]byte, 3)
|
seperatorBytes := make([]byte, 3)
|
||||||
_, err = reader.Read(seperatorBytes)
|
_, err = reader.Read(seperatorBytes)
|
||||||
if err != nil {
|
if err == io.EOF {
|
||||||
|
// EOF are handled else where..
|
||||||
|
return reader, false, nil
|
||||||
|
} else if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
_, err = reader.Seek(0, 0)
|
_, err = reader.Seek(0, 0)
|
||||||
|
@ -113,6 +113,20 @@ if [[ $X != $expected ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# handle empty files
|
||||||
|
./yq e '.' examples/empty.yaml
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
echo "Expected no error when processing empty file but got one"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat examples/empty.yaml | ./yq e '.' -
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
echo "Expected no error when processing empty stdin but got one"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo "--success"
|
echo "--success"
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
Loading…
Reference in New Issue
Block a user