From 06fe07e7ad8fb64b3e73a97598575a17a3ad5316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Mon, 14 Jun 2021 23:40:03 +0200 Subject: [PATCH] #3163: Correct Var::parse null value --- Foundation/src/Var.cpp | 5 +++-- Foundation/testsuite/src/VarTest.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Foundation/src/Var.cpp b/Foundation/src/Var.cpp index 4908d7ee4..4398292ac 100644 --- a/Foundation/src/Var.cpp +++ b/Foundation/src/Var.cpp @@ -432,9 +432,10 @@ Var Var::parse(const std::string& val, std::string::size_type& pos) std::string str = parseString(val, pos); if (str == "false") return false; - - if (str == "true") + else if (str == "true") return true; + else if (str == "null") + return Var(); bool isNumber = false; bool isSigned = false; diff --git a/Foundation/testsuite/src/VarTest.cpp b/Foundation/testsuite/src/VarTest.cpp index a476fb8ac..5a926dd8c 100644 --- a/Foundation/testsuite/src/VarTest.cpp +++ b/Foundation/testsuite/src/VarTest.cpp @@ -2623,9 +2623,9 @@ void VarTest::testJSONDeserializeString() a = Var::parse(tst); assertTrue (a.toString() == "{ \"a\": \"1\", \"b\": \"2\" }"); - tst = "{ \"message\": \"escape\\b\\f\\n\\r\\t\", \"path\": \"\\/dev\\/null\" }"; + tst = "{ \"message\": \"escape\\b\\f\\n\\r\\t\", \"path\": \"\\/dev\\/null\", \"zero\": null }"; a = Var::parse(tst); - assertTrue(a.toString() == "{ \"message\": \"escape\\b\\f\\n\\r\\t\", \"path\": \"/dev/null\" }"); + assertTrue(a.toString() == "{ \"message\": \"escape\\b\\f\\n\\r\\t\", \"path\": \"/dev/null\", \"zero\": null }"); }