How this Greek island loved by 70s rockstars has become the ideal spot for a multi-gen getaway, with great food, friendly locals and stunning scenery
How hot Essex will get this week amid four-day EXTREME heat weather warning?
How hot Essex will get this week amid four-day EXTREME heat weather warning?
Jennifer Lopez enjoys concert night with Ben Affleck's child Fin and her own child Oskar
Row of homes caught in 'devastating' Basildon fire
US Olympian who was arrested for allegedly vandalizing Reflecting Pool hits back at Trump's 'lies' and shares new photo... as dramatic video shows confrontation with cops
'Tutor' Who Took Online Tests for 124 Students Jailed for Three Years
Read more of this story at Slashdot.
Miranda Hart reveals her 'absolute biggest regret' - and how she gave into 'societal pressure'
Essex dad died months after collapse when daughter heard 'weird noises'
Hotel boss sounds alarm over Labour's attack on job creation and investment
Concertgoer, 51, who plunged to his death at Madison Square Garden is identified as 'much-loved' dad-of-two
British mother, 29, has appendix 'wrongly removed' during Egypt holiday
Roy Keane rips into Belgium after 'rubbish' Iran draw - while former stars call out Kevin De Bruyne and co. as they risk early World Cup exit
Revealed: The 'secret' plasterer dad who walked out on Callum Turner as a toddler - and had a second family in Australia, leaving the new Mr Dua Lipa to be raised by his single mum on a tough London council estate
Rogue landlords who fail to fix problems face fines of up to £7,000
Johnny Depp's ex Amber Heard gives rare glimpse of daughter Oonagh, five, after finishing 10k race in Spain
Russell Brand says he couldn't have sexually assaulted a film worker on set of flop Arthur... because he was 'too in love' with Katy Perry to even look at another woman
'Air Miles Andy' is back: Shamed royal took a private jet for a freebie weekend away to a French stud farm hosted by a mega rich Dubai businessman... and enjoyed fine wine, boules and horse riding on the beach
Anti-woke cop calls for new rules amid storm over 'two-tier policing' following murder of teenager Henry Nowak
CodeSOD: When False is True
Lillith was integrating some new tools into an existing Ruby on Rails API. The existing API allowed you to send a dry_run flag along with the request, so that you could have the service calculate its changes without applying them.
The problem was, the new tool Lillith was integrating could send, in the body of the request, {"dry_run": false}, but the service would see it as true. Consistently.
The helper method which checked for "true" parameters looked like this:
def param_true?(param_name) param_value = params[param_name] params.key?(param_name) && (!param_value || param_value.to_s.downcase == 'true') endThe purpose of this function is to handle stringy or nil inputs gracefully. And there's one thing I can say about the function: it will always identify a true value correctly. If your false value is a string, "false", it also works. But that pesky !param_value mean that any actual boolean false value will be seen as true.
This function has been in wide use through the application. Lillith's best guess is that up to this point, no one had set the dry run flag on anything but GET requests, where everything was strings. On POST/PATCH/PUT requests, where the data was passed in the body as JSON, it got parsed into actual boolean values, and thus failed.
That's the WTF, certainly, that this function was lurking and waiting to cause this confusion. But the annoying thing in this function is that it fetches the value from the associative array, then calls params.key? to see if the key exists. That's fine, since Ruby just returns a nil if a key doesn't exist, it's just annoying. I hate to see it. This is, admittedly, more of a "me" problem, but I hate it.