aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-19 22:26:06 +0800
committerGitHub <noreply@github.com>2018-02-19 22:26:06 +0800
commit839acafb9590c24da9446fc66f8a26939210eeb3 (patch)
tree59d3cb61d7b4e470960eb87aa946fb6e24062b3c
parent3f7e82d00ba6b0a9c1e7644b8613aa2126498893 (diff)
parent1d4547ab037db2f21fcb31219ae28a1d295ab270 (diff)
downloaddexon-solidity-839acafb9590c24da9446fc66f8a26939210eeb3.tar
dexon-solidity-839acafb9590c24da9446fc66f8a26939210eeb3.tar.gz
dexon-solidity-839acafb9590c24da9446fc66f8a26939210eeb3.tar.bz2
dexon-solidity-839acafb9590c24da9446fc66f8a26939210eeb3.tar.lz
dexon-solidity-839acafb9590c24da9446fc66f8a26939210eeb3.tar.xz
dexon-solidity-839acafb9590c24da9446fc66f8a26939210eeb3.tar.zst
dexon-solidity-839acafb9590c24da9446fc66f8a26939210eeb3.zip
Merge pull request #3502 from aarlt/minor_fix_no_input_sources_specified
Minor improvement: Check sources
-rw-r--r--Changelog.md2
-rw-r--r--libsolidity/interface/StandardCompiler.cpp6
-rw-r--r--test/libsolidity/StandardCompiler.cpp36
3 files changed, 42 insertions, 2 deletions
diff --git a/Changelog.md b/Changelog.md
index d4e91c26..c856839e 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -6,7 +6,7 @@ Features:
Bugfixes:
-
+ * Standard JSON: catch errors properly when invalid "sources" are passed
### 0.4.20 (2018-02-14)
diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp
index 04f5bd25..84dedfb8 100644
--- a/libsolidity/interface/StandardCompiler.cpp
+++ b/libsolidity/interface/StandardCompiler.cpp
@@ -236,7 +236,11 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
return formatFatalError("JSONError", "Only \"Solidity\" is supported as a language.");
Json::Value const& sources = _input["sources"];
- if (!sources)
+
+ if (!sources.isObject() && !sources.isNull())
+ return formatFatalError("JSONError", "\"sources\" is not a JSON object.");
+
+ if (sources.empty())
return formatFatalError("JSONError", "No input sources specified.");
Json::Value errors = Json::arrayValue;
diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp
index e48624e5..8da536d8 100644
--- a/test/libsolidity/StandardCompiler.cpp
+++ b/test/libsolidity/StandardCompiler.cpp
@@ -154,6 +154,42 @@ BOOST_AUTO_TEST_CASE(no_sources)
BOOST_CHECK(containsError(result, "JSONError", "No input sources specified."));
}
+BOOST_AUTO_TEST_CASE(no_sources_empty_object)
+{
+ char const* input = R"(
+ {
+ "language": "Solidity",
+ "sources": {}
+ }
+ )";
+ Json::Value result = compile(input);
+ BOOST_CHECK(containsError(result, "JSONError", "No input sources specified."));
+}
+
+BOOST_AUTO_TEST_CASE(no_sources_empty_array)
+{
+ char const* input = R"(
+ {
+ "language": "Solidity",
+ "sources": []
+ }
+ )";
+ Json::Value result = compile(input);
+ BOOST_CHECK(containsError(result, "JSONError", "\"sources\" is not a JSON object."));
+}
+
+BOOST_AUTO_TEST_CASE(sources_is_array)
+{
+ char const* input = R"(
+ {
+ "language": "Solidity",
+ "sources": ["aa", "bb"]
+ }
+ )";
+ Json::Value result = compile(input);
+ BOOST_CHECK(containsError(result, "JSONError", "\"sources\" is not a JSON object."));
+}
+
BOOST_AUTO_TEST_CASE(smoke_test)
{
char const* input = R"(