Skip to content

Commit ee57997

Browse files
committed
Minor improvement: check sources
- returns error, if "sources" is an array, an empty object or not defined - Added new test-cases in test/libsolidity/StandardCompiler.cpp
1 parent 834dac7 commit ee57997

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

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 input 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 input 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 input 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)