Skip to content

Commit c6d02f0

Browse files
kmoensgesellix
authored andcommitted
bugfix: parsing a bind mount (short syntax) which contains a 0 in its name fai
1 parent f774573 commit c6d02f0

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

src/main/kotlin/de/gesellix/docker/compose/adapters/ListToServiceVolumesAdapter.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,19 @@ class ListToServiceVolumesAdapter {
4848
target = value))
4949
}
5050

51-
val endOfSpec = '0'
52-
val spec = "$value$endOfSpec"
53-
5451
val volume = ServiceVolume()
5552
var buf = ""
56-
for (char in spec) {
53+
for (char in value) {
5754
buf = if (isWindowsDrive(buf, char)) {
5855
"$buf$char"
59-
} else if (char == ':' || char == endOfSpec) {
60-
populateFieldFromBuffer(char, buf, volume)
56+
} else if (char == ':') {
57+
populateFieldFromBuffer(false, buf, volume)
6158
""
6259
} else {
6360
"$buf$char"
6461
}
6562
}
63+
populateFieldFromBuffer(true, buf, volume)
6664

6765
populateType(volume)
6866
return listOf(volume)
@@ -122,12 +120,12 @@ class ListToServiceVolumesAdapter {
122120
// return firstTwoChars.first().isLetter() && firstTwoChars.last() == ':'
123121
}
124122

125-
private fun populateFieldFromBuffer(char: Char, buffer: String, volume: ServiceVolume) {
126-
if (buffer.isEmpty()) {
123+
private fun populateFieldFromBuffer(endOfInput: Boolean, buffer: String, volume: ServiceVolume) {
124+
if (!endOfInput && buffer.isEmpty()) {
127125
throw IllegalStateException("empty section between colons")
128126
}
129127

130-
if (volume.source.isEmpty() && char == '0') {
128+
if (volume.source.isEmpty() && endOfInput) {
131129
volume.target = buffer
132130
return
133131
} else if (volume.source.isEmpty()) {
@@ -138,7 +136,7 @@ class ListToServiceVolumesAdapter {
138136
return
139137
}
140138

141-
if (char == ':') {
139+
if (!endOfInput) {
142140
throw IllegalStateException("too many colons")
143141
}
144142

src/test/kotlin/de/gesellix/docker/compose/ComposeFileReaderTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,33 @@ class ComposeFileReaderTest : DescribeSpec({
219219
}
220220
}
221221

222+
context("volumes_zeroinpath/sample.yaml") {
223+
224+
val composeFile = ComposeFileReaderTest::class.java.getResource("volumes_zeroinpath/sample.yaml")
225+
val workingDir = Paths.get(composeFile.toURI()).parent.toString()
226+
val result = ComposeFileReader().load(composeFile.openStream(), workingDir, System.getenv())!!
227+
228+
it("should parse source and target correctly") {
229+
assertEquals(ServiceVolumeType.TypeBind.typeName, result.services!!.getValue("foo").volumes!!.first().type)
230+
assertEquals("/data/shared_apps/app/acc-70/data", result.services!!.getValue("foo").volumes!!.first().source)
231+
assertEquals("/data", result.services!!.getValue("foo").volumes!!.first().target)
232+
}
233+
}
234+
235+
context("volumes_readonly_shortsyntax/sample.yaml") {
236+
237+
val composeFile = ComposeFileReaderTest::class.java.getResource("volumes_readonly_shortsyntax/sample.yaml")
238+
val workingDir = Paths.get(composeFile.toURI()).parent.toString()
239+
val result = ComposeFileReader().load(composeFile.openStream(), workingDir, System.getenv())!!
240+
241+
it("should parse source and target correctly") {
242+
assertEquals(ServiceVolumeType.TypeBind.typeName, result.services!!.getValue("foo").volumes!!.first().type)
243+
assertEquals("/data/shared_apps/app/acc/data", result.services!!.getValue("foo").volumes!!.first().source)
244+
assertEquals("/data", result.services!!.getValue("foo").volumes!!.first().target)
245+
assertTrue(result.services!!.getValue("foo").volumes!!.first().readOnly)
246+
}
247+
}
248+
222249
context("volumes_nocopy/sample.yaml") {
223250

224251
val composeFile = ComposeFileReaderTest::class.java.getResource("volumes_nocopy/sample.yaml")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "3"
2+
services:
3+
foo:
4+
image: busybox
5+
volumes:
6+
- '/data/shared_apps/app/acc/data:/data:ro'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "3"
2+
services:
3+
foo:
4+
image: busybox
5+
volumes:
6+
- '/data/shared_apps/app/acc-70/data:/data'

0 commit comments

Comments
 (0)