diff --git a/libdevcore/JSON.cpp b/libdevcore/JSON.cpp index 80c116bbe..5d1ea831d 100644 --- a/libdevcore/JSON.cpp +++ b/libdevcore/JSON.cpp @@ -111,16 +111,4 @@ bool jsonParseStrict(string const& _input, Json::Value& _json, string* _errs /* return parse(readerBuilder, _input, _json, _errs); } -bool jsonParse(string const& _input, Json::Value& _json, string *_errs /* = nullptr */) -{ - static Json::CharReaderBuilder readerBuilder; - return parse(readerBuilder, _input, _json, _errs); -} - -bool jsonParseFile(string const& _fileName, Json::Value& _json, string *_errs /* = nullptr */) -{ - return jsonParse(readFileAsString(_fileName), _json, _errs); -} - - } // namespace dev diff --git a/libdevcore/JSON.h b/libdevcore/JSON.h index ecb934673..2390d55f2 100644 --- a/libdevcore/JSON.h +++ b/libdevcore/JSON.h @@ -41,18 +41,4 @@ std::string jsonCompactPrint(Json::Value const& _input); /// \return \c true if the document was successfully parsed, \c false if an error occurred. bool jsonParseStrict(std::string const& _input, Json::Value& _json, std::string* _errs = nullptr); -/// Parse a JSON string (@a _input) and writes resulting JSON object to (@a _json) -/// \param _input JSON input string -/// \param _json [out] resulting JSON object -/// \param _errs [out] Formatted error messages -/// \return \c true if the document was successfully parsed, \c false if an error occurred. -bool jsonParse(std::string const& _input, Json::Value& _json, std::string* _errs = nullptr); - -/// Parse a JSON string (@a _input) and writes resulting JSON object to (@a _json) -/// \param _input file containing JSON input -/// \param _json [out] resulting JSON object -/// \param _errs [out] Formatted error messages -/// \return \c true if the document was successfully parsed, \c false if an error occurred. -bool jsonParseFile(std::string const& _fileName, Json::Value& _json, std::string* _errs = nullptr); - } diff --git a/libyul/AsmAnalysisInfo.h b/libyul/AsmAnalysisInfo.h index 08a35ade0..1201399a2 100644 --- a/libyul/AsmAnalysisInfo.h +++ b/libyul/AsmAnalysisInfo.h @@ -22,8 +22,6 @@ #include -#include - #include #include #include diff --git a/test/libdevcore/JSON.cpp b/test/libdevcore/JSON.cpp index a3e081be6..684fd92b2 100644 --- a/test/libdevcore/JSON.cpp +++ b/test/libdevcore/JSON.cpp @@ -69,47 +69,6 @@ BOOST_AUTO_TEST_CASE(json_compact_print) BOOST_CHECK("{\"1\":1,\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":2}}" == jsonCompactPrint(json)); } -BOOST_AUTO_TEST_CASE(parse_json_not_strict) -{ - Json::Value json; - std::string errors; - - // just parse a valid json input - BOOST_CHECK(jsonParse("{\"1\":1,\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":2}}", json, &errors)); - BOOST_CHECK(json["1"] == 1); - BOOST_CHECK(json["2"] == "2"); - BOOST_CHECK(json["3"]["3.1"] == "3.1"); - BOOST_CHECK(json["3"]["3.2"] == 2); - - // trailing garbage is allowed here - BOOST_CHECK(jsonParse("{\"1\":2,\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":3}}}}}}}}}}", json, &errors)); - BOOST_CHECK(json["1"] == 2); - BOOST_CHECK(json["2"] == "2"); - BOOST_CHECK(json["3"]["3.1"] == "3.1"); - BOOST_CHECK(json["3"]["3.2"] == 3); - - // comments are allowed - BOOST_CHECK(jsonParse( - "{\"1\":3, // awesome comment\n\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":4}}", json, &errors - )); - BOOST_CHECK(json["1"] == 3); - BOOST_CHECK(json["2"] == "2"); - BOOST_CHECK(json["3"]["3.1"] == "3.1"); - BOOST_CHECK(json["3"]["3.2"] == 4); - - // root element other than object or array is allowed - BOOST_CHECK(jsonParse("[]", json, &errors)); - BOOST_CHECK(jsonParse("{}", json, &errors)); - BOOST_CHECK(jsonParse("1", json, &errors)); - BOOST_CHECK(json == 1); - BOOST_CHECK(jsonParse("\"hello\"", json, &errors)); - BOOST_CHECK(json == "hello"); - - // non-UTF-8 escapes allowed - BOOST_CHECK(jsonParse("[ \"\x80\xec\x80\" ]", json, &errors)); - BOOST_CHECK(json[0] == "\x80\xec\x80"); -} - BOOST_AUTO_TEST_CASE(parse_json_strict) { Json::Value json; diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp index 2526dd8b6..f0af8b544 100644 --- a/test/libsolidity/Metadata.cpp +++ b/test/libsolidity/Metadata.cpp @@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE(metadata_useLiteralContent) BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed"); string metadata_str = compilerStack.metadata("test"); Json::Value metadata; - jsonParse(metadata_str, metadata); + jsonParseStrict(metadata_str, metadata); BOOST_CHECK(dev::test::isValidMetadata(metadata_str)); BOOST_CHECK(metadata.isMember("settings")); if (_literal) diff --git a/test/libsolidity/SMTCheckerJSONTest.cpp b/test/libsolidity/SMTCheckerJSONTest.cpp index a2ce4e26b..19bdcaacc 100644 --- a/test/libsolidity/SMTCheckerJSONTest.cpp +++ b/test/libsolidity/SMTCheckerJSONTest.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,7 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename, langutil::EVMVersion _ev string jsonFilename = _filename.substr(0, _filename.size() - 4) + ".json"; if ( - !jsonParseFile(jsonFilename, m_smtResponses) || + !jsonParseStrict(readFileAsString(jsonFilename), m_smtResponses) || !m_smtResponses.isObject() ) BOOST_THROW_EXCEPTION(runtime_error("Invalid JSON file.")); @@ -158,7 +159,7 @@ Json::Value SMTCheckerTest::buildJson(string const& _extra) sources += "}"; string input = "{" + language + ", " + sources + "}"; Json::Value source; - if (!jsonParse(input, source)) + if (!jsonParseStrict(input, source)) BOOST_THROW_EXCEPTION(runtime_error("Could not build JSON from string: " + input)); return source; }