mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Fixed bad yaml handling
This commit is contained in:
parent
4dbe3636c2
commit
6ec8386f9e
@ -539,6 +539,20 @@ func TestReadCmd_Verbose(t *testing.T) {
|
|||||||
// test.AssertResult(t, "2\n", result.Output)
|
// test.AssertResult(t, "2\n", result.Output)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
func TestReadBadDataCmd(t *testing.T) {
|
||||||
|
content := `[!Whatever]`
|
||||||
|
filename := test.WriteTempYamlFile(content)
|
||||||
|
defer test.RemoveTempYamlFile(filename)
|
||||||
|
|
||||||
|
cmd := getRootCommand()
|
||||||
|
result := test.RunCmd(cmd, fmt.Sprintf("read %s", filename))
|
||||||
|
if result.Error == nil {
|
||||||
|
t.Error("Expected command to fail due to invalid path")
|
||||||
|
}
|
||||||
|
expectedOutput := `yaml: line 1: did not find expected ',' or ']'`
|
||||||
|
test.AssertResult(t, expectedOutput, result.Error.Error())
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadSplatPrefixCmd(t *testing.T) {
|
func TestReadSplatPrefixCmd(t *testing.T) {
|
||||||
content := `a: 2
|
content := `a: 2
|
||||||
b:
|
b:
|
||||||
|
@ -25,12 +25,19 @@ func readYamlFile(filename string, path string, updateAll bool, docIndexInt int)
|
|||||||
|
|
||||||
if errorReading == io.EOF {
|
if errorReading == io.EOF {
|
||||||
return handleEOF(updateAll, docIndexInt, currentIndex)
|
return handleEOF(updateAll, docIndexInt, currentIndex)
|
||||||
|
} else if errorReading != nil {
|
||||||
|
return errorReading
|
||||||
}
|
}
|
||||||
|
|
||||||
var errorParsing error
|
var errorParsing error
|
||||||
matchingNodes, errorParsing = appendDocument(matchingNodes, dataBucket, path, updateAll, docIndexInt, currentIndex)
|
matchingNodes, errorParsing = appendDocument(matchingNodes, dataBucket, path, updateAll, docIndexInt, currentIndex)
|
||||||
if errorParsing != nil {
|
if errorParsing != nil {
|
||||||
return errorParsing
|
return errorParsing
|
||||||
}
|
}
|
||||||
|
if !updateAll && currentIndex == docIndexInt {
|
||||||
|
log.Debug("all done")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
currentIndex = currentIndex + 1
|
currentIndex = currentIndex + 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
8
examples/bad.yaml
Normal file
8
examples/bad.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
b:
|
||||||
|
d: be gone
|
||||||
|
c: 2
|
||||||
|
e:
|
||||||
|
- name: Billy Bob # comment over here
|
||||||
|
|
||||||
|
---
|
||||||
|
[123123
|
Loading…
Reference in New Issue
Block a user