Generalising the empty array fix to map

This commit is contained in:
Mike Farah
2026-08-03 13:31:47 +10:00
parent b74aefd55f
commit 7862131c9c
5 changed files with 19 additions and 7 deletions
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+4 -3
View File
@@ -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)
}
+11
View File
@@ -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",