Skip to content

Commit 839acaf

Browse files
authored
Merge pull request #3502 from aarlt/minor_fix_no_input_sources_specified
Minor improvement: Check sources
2 parents 3f7e82d + 1d4547a commit 839acaf

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Features:
66

77

88
Bugfixes:
9-
9+
* Standard JSON: catch errors properly when invalid "sources" are passed
1010

1111
### 0.4.20 (2018-02-14)
1212

libsolidity/interface/StandardCompiler.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
236236
return formatFatalError("JSONError", "Only \"Solidity\" is supported as a language.");
237237

238238
Json::Value const& sources = _input["sources"];
239-
if (!sources)
239+
240+
if (!sources.isObject() && !sources.isNull())
241+
return formatFatalError("JSONError", "\"sources\" is not a JSON object.");
242+
243+
if (sources.empty())
240244
return formatFatalError("JSONError", "No input sources specified.");
241245

242246
Json::Value errors = Json::arrayValue;

test/libsolidity/StandardCompiler.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,42 @@ BOOST_AUTO_TEST_CASE(no_sources)
154154
BOOST_CHECK(containsError(result, "JSONError", "No input sources specified."));
155155
}
156156

157+
BOOST_AUTO_TEST_CASE(no_sources_empty_object)
158+
{
159+
char const* input = R"(
160+
{
161+
"language": "Solidity",
162+
"sources": {}
163+
}
164+
)";
165+
Json::Value result = compile(input);
166+
BOOST_CHECK(containsError(result, "JSONError", "No input sources specified."));
167+
}
168+
169+
BOOST_AUTO_TEST_CASE(no_sources_empty_array)
170+
{
171+
char const* input = R"(
172+
{
173+
"language": "Solidity",
174+
"sources": []
175+
}
176+
)";
177+
Json::Value result = compile(input);
178+
BOOST_CHECK(containsError(result, "JSONError", "\"sources\" is not a JSON object."));
179+
}
180+
181+
BOOST_AUTO_TEST_CASE(sources_is_array)
182+
{
183+
char const* input = R"(
184+
{
185+
"language": "Solidity",
186+
"sources": ["aa", "bb"]
187+
}
188+
)";
189+
Json::Value result = compile(input);
190+
BOOST_CHECK(containsError(result, "JSONError", "\"sources\" is not a JSON object."));
191+
}
192+
157193
BOOST_AUTO_TEST_CASE(smoke_test)
158194
{
159195
char const* input = R"(

0 commit comments

Comments
 (0)