diff --git a/pkg/yqlib/doc/operators/system-operators.md b/pkg/yqlib/doc/operators/system-operators.md index de0a8caf..df1a76cd 100644 --- a/pkg/yqlib/doc/operators/system-operators.md +++ b/pkg/yqlib/doc/operators/system-operators.md @@ -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 diff --git a/pkg/yqlib/encoder_toml.go b/pkg/yqlib/encoder_toml.go index e5d87ae9..e34fca59 100644 --- a/pkg/yqlib/encoder_toml.go +++ b/pkg/yqlib/encoder_toml.go @@ -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 diff --git a/pkg/yqlib/operator_anchors_aliases_test.go b/pkg/yqlib/operator_anchors_aliases_test.go index df168571..144443e3 100644 --- a/pkg/yqlib/operator_anchors_aliases_test.go +++ b/pkg/yqlib/operator_anchors_aliases_test.go @@ -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 diff --git a/pkg/yqlib/operator_delete.go b/pkg/yqlib/operator_delete.go index 9ac084c7..7fee0fd5 100644 --- a/pkg/yqlib/operator_delete.go +++ b/pkg/yqlib/operator_delete.go @@ -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) } diff --git a/pkg/yqlib/operator_delete_test.go b/pkg/yqlib/operator_delete_test.go index 57eb3ff9..dde63024 100644 --- a/pkg/yqlib/operator_delete_test.go +++ b/pkg/yqlib/operator_delete_test.go @@ -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",