Skip to content

Conversation

gfontenot
Copy link
Collaborator

Servers commonly represent boolean values as numbers even though this is
clearly wrong and they should be sending true/false.

Anyway, we can make it easier to deal with this by allowing numbers to
represent boolean values as well. This essentially fixes compatibility
with earlier versions of Argo, which did this anyway.

Fixes #358

@tonyd256
Copy link
Contributor

tonyd256 commented Apr 6, 2016

👍 do we have a test that can demo this? and possibly a number that fails (if that exists)

@jshier
Copy link
Contributor

jshier commented Apr 6, 2016

Test should be straightforward, just parse this JSON, both as true:

{
  "realBool": true,
  "numberBool": 1
}

As for failure, I can't really think of one for the number case, as any number this isn't 0 (false) will be cast to Bool as true. Aside from overflows, which can't be parsed into a number in the first place.

@gfontenot gfontenot force-pushed the gf-boolean-as-number branch from 6e694bf to 651e3b8 Compare April 7, 2016 23:21
let bool: Bool
let number: Bool

static func decode(j: JSON) -> Decoded<Booleans> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable Name Violation: Variable name should be between 3 and 40 characters long: 'j' (variable_name)

@gfontenot
Copy link
Collaborator Author

Added a success test and fixed the build by writing code that actually compiles (which seemed useful)

Servers commonly represent boolean values as numbers even though this is
clearly wrong and they should be sending `true`/`false`.

Anyway, we can make it easier to deal with this by allowing numbers to
represent boolean values as well. This essentially fixes compatibility
with earlier versions of Argo, which did this anyway.
@gfontenot gfontenot force-pushed the gf-boolean-as-number branch from 2c7594c to a7ca3b5 Compare April 8, 2016 19:13
@gfontenot gfontenot merged commit a7ca3b5 into master Apr 8, 2016
@gfontenot gfontenot deleted the gf-boolean-as-number branch April 8, 2016 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Argo 3 breaks implicit Number -> Bool conversion
4 participants