envsubst: unexpected behaviour for +, = and ?

Open
#911 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
go
Domain
cli

Research direction

Start with the envsubst implementation and the supported syntax described in README. Trace parsing for ${parameter:+word}, ${parameter:=word}, and ${parameter:?word}, then compare the behavior with the linked Bash reference. Done means unsupported operators no longer silently behave like :-, with coverage demonstrating the expected results.

Written by the indexing model from the issue text.

Description

In envsubst, it appears like ${parameter:+word}, ${parameter:=word} and ${parameter:?word} are all treated as if they were${parameter:-word}. According to the README, + and ? are unsupported, but I would expect an error instead of this behaviour.

From the bash reference manual:

  • ${parameter:-word}: If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.
  • ${parameter:=word}: If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.
  • ${parameter:?word}: If parameter is null or unset, the expansion of word (or a message to that effect if word is not present) is written to the standard error and the shell, if it is not interactive, exits. Otherwise, the value of parameter is substituted.
  • ${parameter:+word}: If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.

= and - are quite similar, and will function as expected in most use cases.
? should not substitute anything, but error if unset.
+ currently does the exact opposite of what it's supposed to do.

Dominant language
Go
Stars
63
Forks
162
Avg merge
9h 54m
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fluxcd/pkg

All issues in fluxcd/pkg

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.