Fix detection for missing parameter in substitution
`${}`, `${:}` and so on are invalid because there's no parameter within the brackets; fix detection for this situation and add/update tests. There were some existing test-cases that were testing for the wrong behavior, which are now updated. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> rewritten from github.com/moby/moby 334bf3ea76004d0abe02dd1698989f9eaf87a86adocker-18.09
parent
33114da1da
commit
e15e0ddbf5
|
@ -29,10 +29,14 @@ A|he\$PWD | he$PWD
|
||||||
A|he\\$PWD | he\/home
|
A|he\\$PWD | he\/home
|
||||||
A|"he\$PWD" | he$PWD
|
A|"he\$PWD" | he$PWD
|
||||||
A|"he\\$PWD" | he\/home
|
A|"he\\$PWD" | he\/home
|
||||||
|
A|\${} | ${}
|
||||||
|
A|\${}aaa | ${}aaa
|
||||||
A|he\${} | he${}
|
A|he\${} | he${}
|
||||||
A|he\${}xx | he${}xx
|
A|he\${}xx | he${}xx
|
||||||
A|he${} | he
|
A|${} | error
|
||||||
A|he${}xx | hexx
|
A|${}aaa | error
|
||||||
|
A|he${} | error
|
||||||
|
A|he${}xx | error
|
||||||
A|he${hi} | he
|
A|he${hi} | he
|
||||||
A|he${hi}xx | hexx
|
A|he${hi}xx | hexx
|
||||||
A|he${PWD} | he/home
|
A|he${PWD} | he/home
|
||||||
|
@ -88,8 +92,8 @@ A|안녕\$PWD | 안녕$PWD
|
||||||
A|안녕\\$PWD | 안녕\/home
|
A|안녕\\$PWD | 안녕\/home
|
||||||
A|안녕\${} | 안녕${}
|
A|안녕\${} | 안녕${}
|
||||||
A|안녕\${}xx | 안녕${}xx
|
A|안녕\${}xx | 안녕${}xx
|
||||||
A|안녕${} | 안녕
|
A|안녕${} | error
|
||||||
A|안녕${}xx | 안녕xx
|
A|안녕${}xx | error
|
||||||
A|안녕${hi} | 안녕
|
A|안녕${hi} | 안녕
|
||||||
A|안녕${hi}xx | 안녕xx
|
A|안녕${hi}xx | 안녕xx
|
||||||
A|안녕${PWD} | 안녕/home
|
A|안녕${PWD} | 안녕/home
|
||||||
|
@ -129,4 +133,7 @@ A|${aaa:-bbb} | bbb
|
||||||
A|${aaa:-${bbb:-ccc}} | ccc
|
A|${aaa:-${bbb:-ccc}} | ccc
|
||||||
A|${aaa:-bbb ${foo} | error
|
A|${aaa:-bbb ${foo} | error
|
||||||
A|${aaa:-bbb {foo} | bbb {foo
|
A|${aaa:-bbb {foo} | bbb {foo
|
||||||
|
A|${:} | error
|
||||||
|
A|${:-bbb} | error
|
||||||
|
A|${:+bbb} | error
|
||||||
|
|
||||||
|
|
|
@ -261,23 +261,22 @@ func (sw *shellWord) processDollar() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.scanner.Next()
|
sw.scanner.Next()
|
||||||
|
switch sw.scanner.Peek() {
|
||||||
|
case scanner.EOF:
|
||||||
|
return "", errors.New("syntax error: missing '}'")
|
||||||
|
case '{', '}', ':':
|
||||||
|
// Invalid ${{xx}, ${:xx}, ${:}. ${} case
|
||||||
|
return "", errors.New("syntax error: bad substitution")
|
||||||
|
}
|
||||||
name := sw.processName()
|
name := sw.processName()
|
||||||
ch := sw.scanner.Peek()
|
ch := sw.scanner.Next()
|
||||||
switch ch {
|
switch ch {
|
||||||
case '}':
|
case '}':
|
||||||
// Normal ${xx} case
|
// Normal ${xx} case
|
||||||
sw.scanner.Next()
|
|
||||||
return sw.getEnv(name), nil
|
return sw.getEnv(name), nil
|
||||||
case '{':
|
|
||||||
// Invalid ${{xx} case
|
|
||||||
return "", errors.New("syntax error: bad substitution")
|
|
||||||
case scanner.EOF:
|
|
||||||
return "", errors.New("syntax error: missing '}'")
|
|
||||||
case ':':
|
case ':':
|
||||||
// Special ${xx:...} format processing
|
// Special ${xx:...} format processing
|
||||||
// Yes it allows for recursive $'s in the ... spot
|
// Yes it allows for recursive $'s in the ... spot
|
||||||
|
|
||||||
sw.scanner.Next() // skip over :
|
|
||||||
modifier := sw.scanner.Next()
|
modifier := sw.scanner.Next()
|
||||||
|
|
||||||
word, _, err := sw.processStopOn('}')
|
word, _, err := sw.processStopOn('}')
|
||||||
|
|
Loading…
Reference in New Issue