From d806889c9dcc49e5885942b1de63fae147875dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 26 Feb 2023 22:30:41 +0000 Subject: [PATCH] Revert "syntax: simplify unset-or-null with null default to just unset" Per #970, even if the change is technically correct, it can easily lead to confusion for users or unintentional bugs when they tweak the code without noticing the subtlety between null (empty) and unset values. This reverts commit e8ee47f4575985d0e02ddcc03290499830bdbf6f. Fixes #970. --- syntax/simplify.go | 5 ----- syntax/simplify_test.go | 4 ---- 2 files changed, 9 deletions(-) diff --git a/syntax/simplify.go b/syntax/simplify.go index 5a93966e2..e82fd55af 100644 --- a/syntax/simplify.go +++ b/syntax/simplify.go @@ -16,7 +16,6 @@ import "bytes" // Remove redundant quotes [[ "$var" == str ]] // Merge negations with unary operators [[ ! -n $var ]] // Use single quotes to shorten literals "\$foo" -// Remove redundant param expansion colons ${foo:-} func Simplify(n Node) bool { s := simplifier{} Walk(n, s.visit) @@ -38,10 +37,6 @@ func (s *simplifier) visit(node Node) bool { x.Index = s.removeParensArithm(x.Index) // don't inline params - same as above. - if x.Exp != nil && x.Exp.Op == DefaultUnsetOrNull && x.Exp.Word == nil { - s.modified = true - x.Exp.Op = DefaultUnset - } if x.Slice == nil { break } diff --git a/syntax/simplify_test.go b/syntax/simplify_test.go index aa8ca45a0..4058fff0b 100644 --- a/syntax/simplify_test.go +++ b/syntax/simplify_test.go @@ -67,10 +67,6 @@ var simplifyTests = [...]simplifyTest{ {"\"fo\\`o\"", "'fo`o'"}, noSimple(`fo"o"bar`), noSimple(`foo""bar`), - - // param expansions - {`${foo:-}`, `${foo-}`}, - noSimple(`${foo:-bar}`), } func TestSimplify(t *testing.T) {