aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog.md2
-rw-r--r--libdevcore/CMakeLists.txt4
-rw-r--r--libdevcore/JSON.cpp109
-rw-r--r--libdevcore/JSON.h31
-rw-r--r--libsolc/libsolc.cpp16
-rw-r--r--libsolidity/interface/StandardCompiler.cpp7
-rw-r--r--test/Metadata.cpp2
-rw-r--r--test/RPCSession.cpp14
-rw-r--r--test/fuzzer.cpp6
-rw-r--r--test/libdevcore/JSON.cpp151
-rw-r--r--test/libsolidity/JSONCompiler.cpp6
-rw-r--r--test/libsolidity/Metadata.cpp5
-rw-r--r--test/libsolidity/SolidityABIJSON.cpp5
-rw-r--r--test/libsolidity/SolidityNatspecJSON.cpp5
-rw-r--r--test/libsolidity/StandardCompiler.cpp27
15 files changed, 337 insertions, 53 deletions
diff --git a/Changelog.md b/Changelog.md
index 4e6e1b92..8fa9d93d 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -2,9 +2,9 @@
Features:
* Code Generator: Assert that ``k != 0`` for ``molmod(a, b, k)`` and ``addmod(a, b, k)`` as experimental 0.5.0 feature.
+ * Standard JSON: Reject badly formatted invalid JSON inputs.
* Type Checker: Disallow uninitialized storage pointers as experimental 0.5.0 feature.
-
Bugfixes:
* JSON-AST: Add "documentation" property to function, event and modifier definition.
* Resolver: Properly determine shadowing for imports with aliases.
diff --git a/libdevcore/CMakeLists.txt b/libdevcore/CMakeLists.txt
index a1c4c2d3..d107f701 100644
--- a/libdevcore/CMakeLists.txt
+++ b/libdevcore/CMakeLists.txt
@@ -2,7 +2,9 @@ file(GLOB sources "*.cpp")
file(GLOB headers "*.h")
add_library(devcore ${sources} ${headers})
-target_link_libraries(devcore PRIVATE ${Boost_FILESYSTEM_LIBRARIES} ${Boost_REGEX_LIBRARIES} ${Boost_SYSTEM_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(devcore PRIVATE ${JSONCPP_LIBRARY} ${Boost_FILESYSTEM_LIBRARIES} ${Boost_REGEX_LIBRARIES} ${Boost_SYSTEM_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(devcore SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
target_include_directories(devcore PUBLIC "${CMAKE_SOURCE_DIR}")
+target_include_directories(devcore PUBLIC "${JSONCPP_INCLUDE_DIR}")
+add_dependencies(devcore jsoncpp)
add_dependencies(devcore solidity_BuildInfo.h)
diff --git a/libdevcore/JSON.cpp b/libdevcore/JSON.cpp
new file mode 100644
index 00000000..079d4d51
--- /dev/null
+++ b/libdevcore/JSON.cpp
@@ -0,0 +1,109 @@
+/*
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+/** @file JSON.cpp
+ * @author Alexander Arlt <alexander.arlt@arlt-labs.com>
+ * @date 2018
+ */
+
+#include "JSON.h"
+
+#include <sstream>
+#include <map>
+#include <memory>
+
+using namespace std;
+
+namespace dev
+{
+
+namespace
+{
+
+/// StreamWriterBuilder that can be constructed with specific settings
+class StreamWriterBuilder: public Json::StreamWriterBuilder
+{
+public:
+ explicit StreamWriterBuilder(map<string, string> const& _settings)
+ {
+ for (auto const& iter :_settings)
+ this->settings_[iter.first] = iter.second;
+ }
+};
+
+/// CharReaderBuilder with strict-mode settings
+class StrictModeCharReaderBuilder: public Json::CharReaderBuilder
+{
+public:
+ StrictModeCharReaderBuilder()
+ {
+ Json::CharReaderBuilder::strictMode(&this->settings_);
+ }
+};
+
+/// Serialise the JSON object (@a _input) with specific builder (@a _builder)
+/// \param _input JSON input string
+/// \param _builder StreamWriterBuilder that is used to create new Json::StreamWriter
+/// \return serialized json object
+string print(Json::Value const& _input, Json::StreamWriterBuilder const& _builder)
+{
+ stringstream stream;
+ unique_ptr<Json::StreamWriter> writer(_builder.newStreamWriter());
+ writer->write(_input, &stream);
+ return stream.str();
+}
+
+/// Parse a JSON string (@a _input) with specified builder (@ _builder) and writes resulting JSON object to (@a _json)
+/// \param _builder CharReaderBuilder that is used to create new Json::CharReaders
+/// \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 parse(Json::CharReaderBuilder& _builder, string const& _input, Json::Value& _json, string* _errs)
+{
+ unique_ptr<Json::CharReader> reader(_builder.newCharReader());
+ return reader->parse(_input.c_str(), _input.c_str() + _input.length(), &_json, _errs);
+}
+
+} // end anonymous namespace
+
+string jsonPrettyPrint(Json::Value const& _input)
+{
+ static map<string, string> settings{{"indentation", " "}};
+ static StreamWriterBuilder writerBuilder(settings);
+ return print(_input, writerBuilder);
+}
+
+string jsonCompactPrint(Json::Value const& _input)
+{
+ static map<string, string> settings{{"indentation", ""}};
+ static StreamWriterBuilder writerBuilder(settings);
+ return print(_input, writerBuilder);
+}
+
+bool jsonParseStrict(string const& _input, Json::Value& _json, string* _errs /* = nullptr */)
+{
+ static StrictModeCharReaderBuilder readerBuilder;
+ 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);
+}
+
+} // namespace dev
diff --git a/libdevcore/JSON.h b/libdevcore/JSON.h
index 8499d623..1ce822cd 100644
--- a/libdevcore/JSON.h
+++ b/libdevcore/JSON.h
@@ -24,21 +24,28 @@
#include <json/json.h>
-namespace dev
-{
+#include <string>
+
+namespace dev {
/// Serialise the JSON object (@a _input) with indentation
-inline std::string jsonPrettyPrint(Json::Value const& _input)
-{
- return Json::StyledWriter().write(_input);
-}
+std::string jsonPrettyPrint(Json::Value const& _input);
/// Serialise the JSON object (@a _input) without indentation
-inline std::string jsonCompactPrint(Json::Value const& _input)
-{
- Json::FastWriter writer;
- writer.omitEndingLineFeed();
- return writer.write(_input);
-}
+std::string jsonCompactPrint(Json::Value const& _input);
+
+/// Parse a JSON string (@a _input) with enabled strict-mode 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 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);
}
diff --git a/libsolc/libsolc.cpp b/libsolc/libsolc.cpp
index 3a6e1521..6c587e23 100644
--- a/libsolc/libsolc.cpp
+++ b/libsolc/libsolc.cpp
@@ -203,7 +203,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
{
Json::Value contractInput = ret["contracts"][sourceName][contractName];
Json::Value contractOutput = Json::objectValue;
- contractOutput["interface"] = dev::jsonCompactPrint(contractInput["abi"]);
+ contractOutput["interface"] = jsonCompactPrint(contractInput["abi"]);
contractOutput["metadata"] = contractInput["metadata"];
contractOutput["functionHashes"] = contractInput["evm"]["methodIdentifiers"];
contractOutput["gasEstimates"] = translateGasEstimates(contractInput["evm"]["gasEstimates"]);
@@ -219,7 +219,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
try
{
- return dev::jsonCompactPrint(output);
+ return jsonCompactPrint(output);
}
catch (...)
{
@@ -229,15 +229,15 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
string compileMulti(string const& _input, bool _optimize, CStyleReadFileCallback _readCallback = nullptr)
{
- Json::Reader reader;
+ string errors;
Json::Value input;
- if (!reader.parse(_input, input, false))
+ if (!jsonParseStrict(_input, input, &errors))
{
- Json::Value errors(Json::arrayValue);
- errors.append("Error parsing input JSON: " + reader.getFormattedErrorMessages());
+ Json::Value jsonErrors(Json::arrayValue);
+ jsonErrors.append("Error parsing input JSON: " + errors);
Json::Value output(Json::objectValue);
- output["errors"] = errors;
- return dev::jsonCompactPrint(output);
+ output["errors"] = jsonErrors;
+ return jsonCompactPrint(output);
}
else
{
diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp
index 84dedfb8..fb973d51 100644
--- a/libsolidity/interface/StandardCompiler.cpp
+++ b/libsolidity/interface/StandardCompiler.cpp
@@ -554,12 +554,11 @@ Json::Value StandardCompiler::compile(Json::Value const& _input)
string StandardCompiler::compile(string const& _input)
{
Json::Value input;
- Json::Reader reader;
-
+ string errors;
try
{
- if (!reader.parse(_input, input, false))
- return jsonCompactPrint(formatFatalError("JSONError", reader.getFormattedErrorMessages()));
+ if (!jsonParseStrict(_input, input, &errors))
+ return jsonCompactPrint(formatFatalError("JSONError", errors));
}
catch(...)
{
diff --git a/test/Metadata.cpp b/test/Metadata.cpp
index e4de0a6b..1ebfd468 100644
--- a/test/Metadata.cpp
+++ b/test/Metadata.cpp
@@ -50,7 +50,7 @@ string bytecodeSansMetadata(string const& _bytecode)
bool isValidMetadata(string const& _metadata)
{
Json::Value metadata;
- if (!Json::Reader().parse(_metadata, metadata, false))
+ if (!jsonParseStrict(_metadata, metadata))
return false;
if (
diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp
index 60aafc85..69c75cee 100644
--- a/test/RPCSession.cpp
+++ b/test/RPCSession.cpp
@@ -23,8 +23,7 @@
#include <libdevcore/CommonData.h>
-#include <json/reader.h>
-#include <json/writer.h>
+#include <libdevcore/JSON.h>
#include <string>
#include <stdio.h>
@@ -216,7 +215,7 @@ string RPCSession::personal_newAccount(string const& _password)
void RPCSession::test_setChainParams(vector<string> const& _accounts)
{
- static std::string const c_configString = R"(
+ static string const c_configString = R"(
{
"sealEngine": "NoProof",
"params": {
@@ -249,10 +248,10 @@ void RPCSession::test_setChainParams(vector<string> const& _accounts)
)";
Json::Value config;
- BOOST_REQUIRE(Json::Reader().parse(c_configString, config));
+ BOOST_REQUIRE(jsonParseStrict(c_configString, config));
for (auto const& account: _accounts)
config["accounts"][account]["wei"] = "0x100000000000000000000000000000000000000000";
- test_setChainParams(Json::FastWriter().write(config));
+ test_setChainParams(jsonCompactPrint(config));
}
void RPCSession::test_setChainParams(string const& _config)
@@ -328,7 +327,7 @@ Json::Value RPCSession::rpcCall(string const& _methodName, vector<string> const&
BOOST_TEST_MESSAGE("Reply: " + reply);
Json::Value result;
- BOOST_REQUIRE(Json::Reader().parse(reply, result, false));
+ BOOST_REQUIRE(jsonParseStrict(reply, result));
if (result.isMember("error"))
{
@@ -371,6 +370,5 @@ string RPCSession::TransactionData::toJson() const
json["gasprice"] = gasPrice;
json["value"] = value;
json["data"] = data;
- return Json::FastWriter().write(json);
-
+ return jsonCompactPrint(json);
}
diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp
index 578e63a4..c61410b6 100644
--- a/test/fuzzer.cpp
+++ b/test/fuzzer.cpp
@@ -22,7 +22,7 @@
#include <libevmasm/ConstantOptimiser.h>
#include <libsolc/libsolc.h>
-#include <json/json.h>
+#include <libdevcore/JSON.h>
#include <boost/program_options.hpp>
@@ -101,7 +101,7 @@ void testStandardCompiler()
string input = readInput();
string outputString(compileStandard(input.c_str(), NULL));
Json::Value output;
- if (!Json::Reader().parse(outputString, output))
+ if (!jsonParseStrict(outputString, output))
{
cout << "Compiler produced invalid JSON output." << endl;
abort();
@@ -129,7 +129,7 @@ void testCompiler(bool optimize)
string outputString(compileJSON(input.c_str(), optimize));
Json::Value outputJson;
- if (!Json::Reader().parse(outputString, outputJson))
+ if (!jsonParseStrict(outputString, outputJson))
{
cout << "Compiler produced invalid JSON output." << endl;
abort();
diff --git a/test/libdevcore/JSON.cpp b/test/libdevcore/JSON.cpp
new file mode 100644
index 00000000..39d71b42
--- /dev/null
+++ b/test/libdevcore/JSON.cpp
@@ -0,0 +1,151 @@
+/*
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+/**
+ * @date 2018
+ * Unit tests for JSON.h.
+ */
+
+#include <libdevcore/JSON.h>
+
+#include "../TestHelper.h"
+
+using namespace std;
+
+namespace dev
+{
+namespace test
+{
+
+BOOST_AUTO_TEST_SUITE(JsonTest)
+
+BOOST_AUTO_TEST_CASE(json_pretty_print)
+{
+ Json::Value json;
+ Json::Value jsonChild;
+
+ jsonChild["3.1"] = "3.1";
+ jsonChild["3.2"] = 2;
+ json["1"] = 1;
+ json["2"] = "2";
+ json["3"] = jsonChild;
+
+ BOOST_CHECK(
+ "{\n"
+ " \"1\" : 1,\n"
+ " \"2\" : \"2\",\n"
+ " \"3\" : \n"
+ " {\n"
+ " \"3.1\" : \"3.1\",\n"
+ " \"3.2\" : 2\n"
+ " }\n"
+ "}" == jsonPrettyPrint(json));
+}
+
+BOOST_AUTO_TEST_CASE(json_compact_print)
+{
+ Json::Value json;
+ Json::Value jsonChild;
+
+ jsonChild["3.1"] = "3.1";
+ jsonChild["3.2"] = 2;
+ json["1"] = 1;
+ json["2"] = "2";
+ json["3"] = jsonChild;
+
+ 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;
+ std::string errors;
+
+ // just parse a valid json input
+ BOOST_CHECK(jsonParseStrict("{\"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 not allowed in strict-mode
+ BOOST_CHECK(!jsonParseStrict("{\"1\":2,\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":3}}}}}}}}}}", json, &errors));
+
+ // comments are allowed in strict-mode? - that's strange...
+ BOOST_CHECK(jsonParseStrict(
+ "{\"1\":3, // awesome comment\n\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":5}}", 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"] == 5);
+
+ // root element can only be object or array
+ BOOST_CHECK(jsonParseStrict("[]", json, &errors));
+ BOOST_CHECK(jsonParseStrict("{}", json, &errors));
+ BOOST_CHECK(!jsonParseStrict("1", json, &errors));
+ BOOST_CHECK(!jsonParseStrict("\"hello\"", json, &errors));
+
+ // non-UTF-8 escapes allowed??
+ BOOST_CHECK(jsonParseStrict("[ \"\x80\xec\x80\" ]", json, &errors));
+ BOOST_CHECK(json[0] == "\x80\xec\x80");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+}
+}
diff --git a/test/libsolidity/JSONCompiler.cpp b/test/libsolidity/JSONCompiler.cpp
index 0c904c77..285c5604 100644
--- a/test/libsolidity/JSONCompiler.cpp
+++ b/test/libsolidity/JSONCompiler.cpp
@@ -44,7 +44,7 @@ Json::Value compileSingle(string const& _input)
{
string output(compileJSON(_input.c_str(), dev::test::Options::get().optimize));
Json::Value ret;
- BOOST_REQUIRE(Json::Reader().parse(output, ret, false));
+ BOOST_REQUIRE(jsonParseStrict(output, ret));
return ret;
}
@@ -56,7 +56,7 @@ Json::Value compileMulti(string const& _input, bool _callback)
compileJSONMulti(_input.c_str(), dev::test::Options::get().optimize)
);
Json::Value ret;
- BOOST_REQUIRE(Json::Reader().parse(output, ret, false));
+ BOOST_REQUIRE(jsonParseStrict(output, ret));
return ret;
}
@@ -64,7 +64,7 @@ Json::Value compile(string const& _input)
{
string output(compileStandard(_input.c_str(), NULL));
Json::Value ret;
- BOOST_REQUIRE(Json::Reader().parse(output, ret, false));
+ BOOST_REQUIRE(jsonParseStrict(output, ret));
return ret;
}
diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp
index efe8faff..47cf1d3d 100644
--- a/test/libsolidity/Metadata.cpp
+++ b/test/libsolidity/Metadata.cpp
@@ -23,6 +23,7 @@
#include "../TestHelper.h"
#include <libsolidity/interface/CompilerStack.h>
#include <libdevcore/SwarmHash.h>
+#include <libdevcore/JSON.h>
namespace dev
{
@@ -111,7 +112,7 @@ BOOST_AUTO_TEST_CASE(metadata_relevant_sources)
std::string const& serialisedMetadata = compilerStack.metadata("A");
BOOST_CHECK(dev::test::isValidMetadata(serialisedMetadata));
Json::Value metadata;
- BOOST_REQUIRE(Json::Reader().parse(serialisedMetadata, metadata, false));
+ BOOST_REQUIRE(jsonParseStrict(serialisedMetadata, metadata));
BOOST_CHECK_EQUAL(metadata["sources"].size(), 1);
BOOST_CHECK(metadata["sources"].isMember("A"));
@@ -149,7 +150,7 @@ BOOST_AUTO_TEST_CASE(metadata_relevant_sources_imports)
std::string const& serialisedMetadata = compilerStack.metadata("C");
BOOST_CHECK(dev::test::isValidMetadata(serialisedMetadata));
Json::Value metadata;
- BOOST_REQUIRE(Json::Reader().parse(serialisedMetadata, metadata, false));
+ BOOST_REQUIRE(jsonParseStrict(serialisedMetadata, metadata));
BOOST_CHECK_EQUAL(metadata["sources"].size(), 3);
BOOST_CHECK(metadata["sources"].isMember("A"));
diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp
index 26bfb6d0..e242508a 100644
--- a/test/libsolidity/SolidityABIJSON.cpp
+++ b/test/libsolidity/SolidityABIJSON.cpp
@@ -26,7 +26,7 @@
#include <libdevcore/Exceptions.h>
#include <libdevcore/SwarmHash.h>
-#include <json/json.h>
+#include <libdevcore/JSON.h>
namespace dev
{
@@ -48,7 +48,7 @@ public:
Json::Value generatedInterface = m_compilerStack.contractABI(m_compilerStack.lastContractName());
Json::Value expectedInterface;
- BOOST_REQUIRE(m_reader.parse(_expectedInterfaceString, expectedInterface));
+ BOOST_REQUIRE(jsonParseStrict(_expectedInterfaceString, expectedInterface));
BOOST_CHECK_MESSAGE(
expectedInterface == generatedInterface,
"Expected:\n" << expectedInterface.toStyledString() <<
@@ -58,7 +58,6 @@ public:
protected:
CompilerStack m_compilerStack;
- Json::Reader m_reader;
};
BOOST_FIXTURE_TEST_SUITE(SolidityABIJSON, JSONInterfaceChecker)
diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp
index fb09451f..e8906bb9 100644
--- a/test/libsolidity/SolidityNatspecJSON.cpp
+++ b/test/libsolidity/SolidityNatspecJSON.cpp
@@ -22,7 +22,7 @@
#include "../TestHelper.h"
#include <string>
-#include <json/json.h>
+#include <libdevcore/JSON.h>
#include <libsolidity/interface/CompilerStack.h>
#include <libsolidity/interface/Exceptions.h>
#include <libdevcore/Exceptions.h>
@@ -55,7 +55,7 @@ public:
else
generatedDocumentation = m_compilerStack.natspecDev(m_compilerStack.lastContractName());
Json::Value expectedDocumentation;
- m_reader.parse(_expectedDocumentationString, expectedDocumentation);
+ jsonParseStrict(_expectedDocumentationString, expectedDocumentation);
BOOST_CHECK_MESSAGE(
expectedDocumentation == generatedDocumentation,
"Expected:\n" << expectedDocumentation.toStyledString() <<
@@ -73,7 +73,6 @@ public:
private:
CompilerStack m_compilerStack;
- Json::Reader m_reader;
};
BOOST_FIXTURE_TEST_SUITE(SolidityNatspecJSON, DocumentationChecker)
diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp
index 8da536d8..404f709d 100644
--- a/test/libsolidity/StandardCompiler.cpp
+++ b/test/libsolidity/StandardCompiler.cpp
@@ -89,7 +89,7 @@ Json::Value compile(string const& _input)
StandardCompiler compiler;
string output = compiler.compile(_input);
Json::Value ret;
- BOOST_REQUIRE(Json::Reader().parse(output, ret, false));
+ BOOST_REQUIRE(jsonParseStrict(output, ret));
return ret;
}
@@ -110,11 +110,11 @@ BOOST_AUTO_TEST_CASE(assume_object_input)
/// Use the string interface of StandardCompiler to trigger these
result = compile("");
- BOOST_CHECK(containsError(result, "JSONError", "* Line 1, Column 1\n Syntax error: value, object or array expected.\n"));
+ BOOST_CHECK(containsError(result, "JSONError", "* Line 1, Column 1\n Syntax error: value, object or array expected.\n* Line 1, Column 1\n A valid JSON document must be either an array or an object value.\n"));
result = compile("invalid");
- BOOST_CHECK(containsError(result, "JSONError", "* Line 1, Column 1\n Syntax error: value, object or array expected.\n"));
+ BOOST_CHECK(containsError(result, "JSONError", "* Line 1, Column 1\n Syntax error: value, object or array expected.\n* Line 1, Column 2\n Extra non-whitespace after JSON value.\n"));
result = compile("\"invalid\"");
- BOOST_CHECK(containsError(result, "JSONError", "Input is not a JSON object."));
+ BOOST_CHECK(containsError(result, "JSONError", "* Line 1, Column 1\n A valid JSON document must be either an array or an object value.\n"));
BOOST_CHECK(!containsError(result, "JSONError", "* Line 1, Column 1\n Syntax error: value, object or array expected.\n"));
result = compile("{}");
BOOST_CHECK(!containsError(result, "JSONError", "* Line 1, Column 1\n Syntax error: value, object or array expected.\n"));
@@ -190,6 +190,25 @@ BOOST_AUTO_TEST_CASE(sources_is_array)
BOOST_CHECK(containsError(result, "JSONError", "\"sources\" is not a JSON object."));
}
+BOOST_AUTO_TEST_CASE(unexpected_trailing_test)
+{
+ char const* input = R"(
+ {
+ "language": "Solidity",
+ "sources": {
+ "A": {
+ "content": "contract A { function f() {} }"
+ }
+ }
+ }
+ }
+ }
+ )";
+ Json::Value result = compile(input);
+ BOOST_CHECK(containsError(result, "JSONError", "* Line 10, Column 2\n Extra non-whitespace after JSON value.\n"));
+}
+
+
BOOST_AUTO_TEST_CASE(smoke_test)
{
char const* input = R"(