From 92f2af5d327e668a2a1d12f013708874b5cdb975 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 12 May 2023 15:21:48 +0200 Subject: [PATCH] [fix] volume can be defined by a numeric ID Signed-off-by: Nicolas De Loof --- loader/loader_test.go | 31 +++++++++++++++++++++++++++++++ loader/volume.go | 3 +++ 2 files changed, 34 insertions(+) diff --git a/loader/loader_test.go b/loader/loader_test.go index cf27efc7..1ae80b05 100644 --- a/loader/loader_test.go +++ b/loader/loader_test.go @@ -2354,3 +2354,34 @@ func TestInvalidProjectNameType(t *testing.T) { assert.Error(t, err, "validating filename0.yml: name must be a string") assert.Assert(t, is.Nil(p)) } + +func TestNumericIDs(t *testing.T) { + p, err := loadYAML(` +name: 'test-numeric-ids' +services: + foo: + image: busybox + volumes: + - 0:/foo + +volumes: + '0': {} +`) + assert.NilError(t, err) + assert.DeepEqual(t, p.Services, types.Services{ + { + Name: "foo", + Image: "busybox", + Environment: types.MappingWithEquals{}, + Scale: 1, + Volumes: []types.ServiceVolumeConfig{ + { + Type: types.VolumeTypeVolume, + Source: "0", + Target: "/foo", + Volume: &types.ServiceVolumeVolume{}, + }, + }, + }, + }) +} diff --git a/loader/volume.go b/loader/volume.go index f1e66cde..dd83414a 100644 --- a/loader/volume.go +++ b/loader/volume.go @@ -176,5 +176,8 @@ func isFilePath(source string) bool { } first, nextIndex := utf8.DecodeRuneInString(source) + if len(source) <= nextIndex { + return false + } return isWindowsDrive([]rune{first}, rune(source[nextIndex])) }