diff --git a/pkg/yqlib/doc/Anchor and Alias Operators.md b/pkg/yqlib/doc/Anchor and Alias Operators.md index dfbdc924..ecfa272c 100644 --- a/pkg/yqlib/doc/Anchor and Alias Operators.md +++ b/pkg/yqlib/doc/Anchor and Alias Operators.md @@ -169,6 +169,22 @@ b: &meow purr a: *meow ``` +## Set alias to blank does nothing +Given a sample.yml file of: +```yaml +b: &meow purr +a: cat +``` +then +```bash +yq eval '.a alias = ""' sample.yml +``` +will output +```yaml +b: &meow purr +a: cat +``` + ## Set alias relatively using assign-update Given a sample.yml file of: ```yaml diff --git a/pkg/yqlib/operator_anchors_aliases_test.go b/pkg/yqlib/operator_anchors_aliases_test.go index bdb24ab2..a611c750 100644 --- a/pkg/yqlib/operator_anchors_aliases_test.go +++ b/pkg/yqlib/operator_anchors_aliases_test.go @@ -90,6 +90,14 @@ var anchorOperatorScenarios = []expressionScenario{ "D0, P[], (doc)::{b: &meow purr, a: *meow}\n", }, }, + { + description: "Set alias to blank does nothing", + document: `{b: &meow purr, a: cat}`, + expression: `.a alias = ""`, + expected: []string{ + "D0, P[], (doc)::{b: &meow purr, a: cat}\n", + }, + }, { skipDoc: true, document: `{b: &meow purr, a: cat}`,