mirror of https://github.com/docker/cli.git
fix panic on single-character volumes
Before this change, this would cause a panic:
docker run -it --rm -v 1:/1 alpine
panic: runtime error: index out of range
goroutine 1 [running]:
github.com/docker/cli/cli/compose/loader.isFilePath(0xc42027e058, 0x1, 0x557dcb978c20)
...
After this change, a correct error is returned:
docker run -it --rm -v 1:/1 alpine
docker: Error response from daemon: create 1: volume name is too short, names should be at least two alphanumeric characters.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 11869fa42a
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d25e657341
commit
4ad65fc358
|
@ -111,6 +111,9 @@ func isFilePath(source string) bool {
|
|||
case '.', '/', '~':
|
||||
return true
|
||||
}
|
||||
if len([]rune(source)) == 1 {
|
||||
return false
|
||||
}
|
||||
|
||||
// windows named pipes
|
||||
if strings.HasPrefix(source, `\\`) {
|
||||
|
|
|
@ -162,6 +162,8 @@ func TestParseVolumeWindowsNamedPipe(t *testing.T) {
|
|||
|
||||
func TestIsFilePath(t *testing.T) {
|
||||
assert.Check(t, !isFilePath("a界"))
|
||||
assert.Check(t, !isFilePath("1"))
|
||||
assert.Check(t, !isFilePath("c"))
|
||||
}
|
||||
|
||||
// Preserve the test cases for VolumeSplitN
|
||||
|
|
Loading…
Reference in New Issue