Skip to content

Commit 9749c52

Browse files
Check invalid environment replacement form like ${VAR:%}
Environment replacement form like below are invalid, so they should cause error. - `${VAR:#pattern}` - `${VAR:##pattern}` - `${VAR:%pattern}` - `${VAR:%%pattern}` Signed-off-by: Mitsuru Kariya <[email protected]>
1 parent 5b5afdb commit 9749c52

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

frontend/dockerfile/shell/lex.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ func (sw *shellWord) processDollar() (string, error) {
378378
fallthrough
379379
case '+', '-', '?', '#', '%':
380380
rawEscapes := ch == '#' || ch == '%'
381+
if nullIsUnset && rawEscapes {
382+
return "", errors.Errorf("unsupported modifier (%s) in substitution", chs)
383+
}
381384
word, _, err := sw.processStopOn('}', rawEscapes)
382385
if err != nil {
383386
if sw.scanner.Peek() == scanner.EOF {

frontend/dockerfile/shell/lex_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,26 @@ func TestProcessWithMatches(t *testing.T) {
497497
expected: "xxyy",
498498
matches: map[string]struct{}{"FOO": {}, "BAR": {}},
499499
},
500+
{
501+
input: "${FOO:#}",
502+
envs: map[string]string{},
503+
expectedErr: true,
504+
},
505+
{
506+
input: "${FOO:##}",
507+
envs: map[string]string{},
508+
expectedErr: true,
509+
},
510+
{
511+
input: "${FOO:%}",
512+
envs: map[string]string{},
513+
expectedErr: true,
514+
},
515+
{
516+
input: "${FOO:%%}",
517+
envs: map[string]string{},
518+
expectedErr: true,
519+
},
500520
{
501521
// test: wildcards
502522
input: "${FOO/$NEEDLE/.} - ${FOO//$NEEDLE/.}",

0 commit comments

Comments
 (0)