Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ extension URIValueFromNodeDecoder {
array = try rootValue(in: values)
}
guard array.count == 1 else {
if style == .simple {
return Substring(array.joined(separator: ","))
}

let reason = array.isEmpty ? "an empty node" : "a node with multiple values"
try throwMismatch("Cannot parse a value from \(reason).")
}
Expand Down
26 changes: 26 additions & 0 deletions Tests/OpenAPIRuntimeTests/URICoder/Decoder/Test_URIDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,30 @@ final class Test_URIDecoder: Test_Runtime {
XCTAssertEqual(decodedValue, nil)
}
}

func testDecoding_percentEncodedCommaToString() throws {
let decoder = URIDecoder(configuration: .simpleUnexplode)

do {
let decodedValue = try decoder.decode(
String.self,
forKey: "",
from: "foo%2C%20bar"
)
XCTAssertEqual(decodedValue, "foo, bar")
}
}

func testDecoding_nonPercentEncodedCommaToString() throws {
let decoder = URIDecoder(configuration: .simpleUnexplode)

do {
let decodedValue = try decoder.decode(
String.self,
forKey: "",
from: "foo, bar"
)
XCTAssertEqual(decodedValue, "foo, bar")
}
}
}