From a9b22c905200b8f6112bf9e275654ce7c7849863 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 8 Oct 2022 10:49:41 -0700 Subject: [PATCH] ircd::lex: Handle js null as falsy boolean. --- ircd/lex_cast.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ircd/lex_cast.cc b/ircd/lex_cast.cc index 43337258b..173d8f486 100644 --- a/ircd/lex_cast.cc +++ b/ircd/lex_cast.cc @@ -219,14 +219,15 @@ ircd::lex_cast(bool i, template<> bool ircd::lex_cast(const string_view &s) { - const bool literal[2] + const bool literal[] { s == "true", s == "false", + s == "null", }; // Handle the common cases early in this frame before call. - if(likely(literal[0] | literal[1])) + if(likely(literal[0] | literal[1] | literal[2])) return literal[0]; return lex::cast(s); @@ -236,14 +237,15 @@ template<> bool ircd::lex_castable(const string_view &s) noexcept { - const bool literal[2] + const bool literal[] { s == "true", s == "false", + s == "null", }; // Handle the common cases early in this frame before call. - if(likely(literal[0] | literal[1])) + if(likely(literal[0] | literal[1] | literal[2])) return true; return lex::test(s);