7 ms·
How can a string of "true" be treated like the boolean value of true? Makes no sense
by arthurcolle 6y ago
How can a string of "true" be treated like the boolean value of true? Makes no sense
- adult_spinach 6y agoThis is probably not the cause, but XML allows using the string "true" and "false" to represent booleans. https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#boolean https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatype...
- fbelzile 6y agoEspecially if it was written in a type safe language like Swift.
- jb1991 6y agoHighly unlikely that Swift is being used to write any backend iCloud services at this point.
- userbinator 6y agoMy guess is there is something "stringly typed" somewhere in the system. A sibling comment mentions Swift, but I doubt all components of iCloud are written in it.
- valleyer 6y agoSwift has "stringly-typed" enumerations (enumerations with backing "raw values" of string type), but it does not treat the enumerations as equal to the strings. Explicit conversion is required. https://docs.swift.org/swift-book/LanguageGuide/Enumerations.html https://docs.swift.org/swift-book/LanguageGuide/Enumerations... 1> let _: Bool = "true" error: repl.swift:1:15: error: cannot convert value of type 'String' to specified type 'Bool' let _: Bool = "true" ^~~~~~
- jjnoakes 6y agoI don't think I'd consider it stringly-typed then. To me, stringly-typed means the type system treats strings and non-strings as convertible to each other implicitly. Strings backing enums seems more like an implementation detail and not a type system feature.
- valleyer 6y agoI see what you're saying, but it's not 100% an implementation detail. The raw values are accessible through the `rawValue` property, which can be useful for serialization, for example. (That could of course be abused to create bugs like the one here.) The reason I say Swift "has" stringly-typed enums is that Objective-C has them (typedefs of NSString where the values are actually strings, and are of course implicitly convertible), and Swift imports them as enums with string-typed raw values. Anyway, I mostly just meant to suggest that this particular iCloud bug is probably not Swift-related.
- dangwu 6y agoI'm pretty sure Apple uses Java for their backend services
- comex 6y agoGoogling the beginning of the error message, "Type error: cannot set value", suggests it's coming from JavaScript code.
- ulucs 6y agoJs doesn't really care about types, and doesn't seem to convert a string "true" into a boolean true: > temp0.innerHTML = true // no error > "true" == true false > true == "true" false
- Izkata 6y agoThe javascript matches are "TypeError" not "Type error", and the more important part of those are "...of null" or "...of undefined". They refer to this: var foo = null; foo.lastName = "anything"; // TypeError, cannot set property "lastName" of null
- rachelbythebay 6y agoHave you seen what happens with YAML when you try to do something like country: xx ... and get to Norway?
- lstamour 6y agoHuh. TIL, thanks! https://yaml.org/type/bool.html https://yaml.org/type/bool.html
- junon 6y agoCongratulations, this is the first actual argument I've seen that has actually made me seriously consider never using YAML again.
- 411111111111111 6y agoThe only thing this should tell you is that unquoted string literals are dangerous in yml.
- kyberias 6y agoAnd because they are dangerous in yaml, the format in itself is dangerous to use. That's why any sane person should seriously consider whether using the format makes sense.
- throwawayboise 6y agoI didn't like YAML from day 1, for this and many other reasons. I never understood why it caught fire like it did.
- pindab0ter 6y agoTOML seems to be catching steam. Would you say that’sa better alternative?
- 6y ago
- sbr464 6y agoI agree. I’ve also noticed the string “[]” breaks random things recently, graphql input values etc (but not a common name thankfully).
- bombcar 6y agoThis becomes amazingly annoying when you’re trying to deal with IPv6 addresses.
- throwawayboise 6y agoEval is evil like that.
- pindab0ter 6y agoWelcome to the wondrous world of dynamically typed languages like PHP and Ruby that are common in backend development. True as you know it can by any of true, “true”, 1, “1”, >0 and most likely more.
- berkes 6y agoNot Ruby, but Rails. And there, it is handled by a clear and dedicated layer: ActiveModel::Type::Boolean.new.cast(value) The only thing you can complain about is that Rails loves implicit magic, which will call this layer for you. Without you needing to set it up, or call it yourself. Many people love this about Rails. (I prefer explicitness over magic.)
- rorykoehler 6y agoOnce you learn rails well enough it all becomes explicit because you can simply read the source code.
- berkes 6y agoExplicit, for me, means that I determine in the model the `published_at` is a DateTime. Not merely in the DB, and never magically derived from the name (_at=datetime, _on=date). But explicitely defined. E.g. `attribute(:published_at, DateTime, default: ->{DateTime.now})` Rails does not do this entirely "magic", though: it derives it from the database. And true: you can follow the logic along: the magic can be researched easily. But still: I really prefer a system in which I write all that boilerplace (my IDE/vim can do this for me really well) instead of relying on convention, heuristics and magic.
- Izkata 6y agoAll inputs in PHP start as strings because you can't tell for certain if a form input was supposed to be 1 or "1", so the language opts to not convert until you trigger it somehow. Combined with PDO for parametrized database queries, if this is PHP this error still should not happen.
- 6y ago
- emsy 6y agoThat’s one of the most common types of errors, it’s literally the number one risk factor according to OWASP: https://owasp.org/www-project-top-ten/ https://owasp.org/www-project-top-ten/
- trav4225 6y agoWelcome to the wonderful world of implicit/dynamic typing. ;-)