Feature Request / Possible bug: Support nested variables enclosed by raw string
- 主要言語
- Go
- スター
- 907
- フォーク
- 96
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I have a weird issue where envsubst is not working as expected.
When I add only a single a default variable to the right side of the experssion it will work similarly as a default POSIX shell. But when I add additional text to the default it start to do some strange behaviour.
I'll provide some examples, I believe that will be the best description.
sh use case:
``` bash
docker run --rm -it debian:buster-slim sh
# export VAR1="shouldevaluate"
# export EMPTY_VAR=""
# export MAIN_VAR="${EMPTY_VAR:-$VAR1}"
# echo $MAIN_VAR
shouldevaluate
#
#
# export MAIN_VAR="${EMPTY_VAR:-asdqwe$VAR1}"
# echo $MAIN_VAR
asdqweshouldevaluate
#
#
# export MAIN_VAR="${EMPTY_VAR:-asdqwe $VAR1 qweasd}"
# echo $MAIN_VAR
asdqwe shouldevaluate qweasd
#
#
# export MAIN_VAR="${EMPTY_VAR:-asdqwe${VAR1}qweasd}"
# echo $MAIN_VAR
asdqweshouldevaluateqweasd
```
And this happens when I try to use the same method in envsubst.
``` bash
# cat test.template
name = ${EMPTY_VAR:-$VAR1}
name = ${EMPTY_VAR:-asdqwe$VAR1}
name = ${EMPTY_VAR:-asdqwe $VAR1 qweasd}
name = ${EMPTY_VAR:-asdqwe${VAR1}qweasd}
#
#
# envsubst < test.template
name = shouldevaluate
name = asdqwe$VAR1
name = asdqwe $VAR1 qweasd
name = asdqwe${VAR1qweasd}
```
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
The issue is about envsubst not correctly handling nested variable expansions within default values, like ${EMPTY_VAR:-asdqwe$VAR1}. Start by examining the parsing logic in the main package, likely in parse.go or subst.go. Look for how default values are processed and where variable substitution within them is applied. Run the provided test cases to reproduce the bug, then modify the parser to recursively evaluate variables inside default strings. Check existing tests in the test suite to ensure changes don't break other substitutions.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- go, shell
- 領域
- cli, tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100