Skip to content

Commit

Permalink
Allow URLEncodedForms to decode 'on' value als Bool => true
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvoorneveld committed Oct 11, 2021
1 parent 2711927 commit 5137fc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Expand Up @@ -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
}
}
Expand Down
8 changes: 8 additions & 0 deletions Tests/VaporTests/URLEncodedFormTests.swift
Expand Up @@ -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 {
Expand Down

0 comments on commit 5137fc8

Please sign in to comment.