Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow URLEncodedForms to decode 'on' value als Bool => true #2698

Merged
merged 4 commits into from Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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