From 5137fc8b191ed48518ea7ff8546075d538ae8e8f Mon Sep 17 00:00:00 2001 From: Bob Voorneveld Date: Thu, 7 Oct 2021 13:45:27 +0200 Subject: [PATCH] Allow URLEncodedForms to decode 'on' value als Bool => true --- .../URLEncodedForm/URLQueryFragmentConvertible.swift | 1 + Tests/VaporTests/URLEncodedFormTests.swift | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Sources/Vapor/URLEncodedForm/URLQueryFragmentConvertible.swift b/Sources/Vapor/URLEncodedForm/URLQueryFragmentConvertible.swift index a907343ab7..6a576cf3bf 100644 --- a/Sources/Vapor/URLEncodedForm/URLQueryFragmentConvertible.swift +++ b/Sources/Vapor/URLEncodedForm/URLQueryFragmentConvertible.swift @@ -78,6 +78,7 @@ extension Bool: URLQueryFragmentConvertible { switch decodedString.lowercased() { case "1", "true": self = true case "0", "false": self = false + case "on": self = true default: return nil } } diff --git a/Tests/VaporTests/URLEncodedFormTests.swift b/Tests/VaporTests/URLEncodedFormTests.swift index 4192e6982d..4610bb284f 100644 --- a/Tests/VaporTests/URLEncodedFormTests.swift +++ b/Tests/VaporTests/URLEncodedFormTests.swift @@ -432,6 +432,14 @@ final class URLEncodedFormTests: XCTestCase { let foo = try URLEncodedFormDecoder().decode(Foo.self, from: "flag") XCTAssertEqual(foo.flag, true) } + + func testFlagIsOnDecodingAsBool() throws { + struct Foo: Codable { + var flag: Bool + } + let foo = try URLEncodedFormDecoder().decode(Foo.self, from: "flag=on") + XCTAssertEqual(foo.flag, true) + } /// https://github.com/vapor/url-encoded-form/issues/3 func testGH3() throws {