Skip to content

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

Compare
Choose a tag to compare
@VaporBot VaporBot released this 18 Jan 17:02
· 127 commits to main since this release
a7d8818
This patch was authored by @bobvoorneveld and released by @Joannis.

When a HTML form uses a checkbox to check something as a Bool, it sends the 'on' value if checked.
The URLEncodedForms decoder should be able to handle that.

<form method="post">
 <input type="checkbox" name="isActive" checked />
 </form>

struct FormData: Decodable {
    let isActive: Bool
}

let formData = try req.content.decode(FormData.self)

fixes #2444