mirror of
https://github.com/mikefarah/yq.git
synced 2026-08-24 00:04:50 +08:00
Generalising the empty array fix to map
This commit is contained in:
@@ -51,7 +51,7 @@ country: Australia
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq --security-enable-system-operator '.country = system("/bin/echo"; "test")' sample.yml
|
||||
yq --security-enable-system-operator '.country = system("/usr/bin/echo"; "test")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
@@ -67,7 +67,7 @@ a: hello
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq --security-enable-system-operator '.a = system("/bin/echo")' sample.yml
|
||||
yq --security-enable-system-operator '.a = system("/usr/bin/echo")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
|
||||
@@ -677,7 +677,7 @@ func (te *tomlEncoder) colorizeToml(input []byte) []byte {
|
||||
|
||||
// Table sections - [section] or [[array]]
|
||||
// Only treat '[' as a table section if it appears at the start of the line
|
||||
// (possibly after whitespace). This avoids incorrectly colouring inline arrays like
|
||||
// (possibly after whitespace). This avoids incorrectly colouring inline arrays like
|
||||
// "ports = [8000, 8001]" as table sections.
|
||||
if ch == '[' {
|
||||
isSectionHeader := true
|
||||
|
||||
@@ -237,7 +237,7 @@ var fixedAnchorOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Merge after explode preserves correct parent references",
|
||||
document: `opensearch: &opensearch-cluster
|
||||
document: `opensearch: &opensearch-cluster
|
||||
ip2geo:
|
||||
enabled: false
|
||||
|
||||
|
||||
@@ -69,10 +69,11 @@ func deleteFromMap(node *CandidateNode, childPath interface{}) {
|
||||
}
|
||||
}
|
||||
node.Content = newContents
|
||||
normaliseEmptyCollectionMapKeyComment(node)
|
||||
}
|
||||
|
||||
func normaliseEmptySequenceMapKeyComment(node *CandidateNode) {
|
||||
if node.Kind != SequenceNode || len(node.Content) != 0 || node.LineComment != "" {
|
||||
func normaliseEmptyCollectionMapKeyComment(node *CandidateNode) {
|
||||
if (node.Kind != SequenceNode && node.Kind != MappingNode) || len(node.Content) != 0 || node.LineComment != "" {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -110,5 +111,5 @@ func deleteFromArray(node *CandidateNode, childPath interface{}) {
|
||||
}
|
||||
}
|
||||
node.Content = newContents
|
||||
normaliseEmptySequenceMapKeyComment(node)
|
||||
normaliseEmptyCollectionMapKeyComment(node)
|
||||
}
|
||||
|
||||
@@ -132,6 +132,17 @@ var deleteOperatorScenarios = []expressionScenario{
|
||||
"D0, P[], (!!map)::testList: [] # A comment\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Delete all entries from map with inline key comment",
|
||||
document: `testMap: # A comment
|
||||
name: test1
|
||||
value: 123`,
|
||||
expression: `del(.testMap[])`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!map)::testMap: {} # A comment\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "Delete entry appended to an array",
|
||||
|
||||
Reference in New Issue
Block a user