Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/Services/ContainerAPIService/Client/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@ public struct Parser {
var directives = defaultDirectives
for part in parts {
let keyVal = part.split(separator: "=", maxSplits: 2)
var key = String(keyVal[0])
guard let rawKey = keyVal.first else {
throw ContainerizationError(.invalidArgument, message: "invalid mount directive '\(part)' in \(mount)")
}
var key = String(rawKey)
var skipValue = false
switch key {
case "type", "size", "mode":
Expand Down
17 changes: 17 additions & 0 deletions Tests/ContainerAPIClientTests/ParserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,23 @@ struct ParserTest {
}
}

@Test
func testMountEmptyDirectiveSegment() throws {
// A comma-segment consisting solely of "=" characters splits to an empty
// array under Swift's default omittingEmptySubsequences, so reading the
// key without a guard would trap. These must surface a validation error.
for input in ["=", "==", "type=bind,=,dst=/foo"] {
#expect {
_ = try Parser.mount(input)
} throws: { error in
guard let error = error as? ContainerizationError else {
return false
}
return error.description.contains("invalid mount directive")
}
}
}

@Test
func testIsValidDomainNameOk() throws {
let names = [
Expand Down