Skip to content

Conversation

@aarlt
Copy link
Collaborator

@aarlt aarlt commented Feb 13, 2018

  • returns error, if "sources" is an array, an empty object or not defined
  • Added new test-cases in test/libsolidity/StandardCompiler.cpp

char const* input = R"(
{
"language": "Solidity",
"sources": []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should result in an error stating it is an invalid input.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its nicely reflected with No input sources specified. - not sufficient?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the other tests it seems we do not have any more granular reporting, so it should be fine for the moment. Can revisit in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait a second, [ "aaa", "bbb" ] will be accepted by the empty-ness check but what will sources.getMemberNames() do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
	"errors" : 
	[
		{
			"component" : "general",
			"formattedMessage" : "JSON logic exception: in Json::Value::getMemberNames(), value must be objectValue",
			"message" : "JSON logic exception: in Json::Value::getMemberNames(), value must be objectValue",
			"severity" : "error",
			"type" : "InternalCompilerError"
		}
	]
}

I guess we need another check for that, another PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just do it in this one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense.

axic
axic previously approved these changes Feb 13, 2018
@aarlt aarlt force-pushed the minor_fix_no_input_sources_specified branch 2 times, most recently from 0eeed12 to f57349d Compare February 14, 2018 08:30
@aarlt aarlt changed the title Minor improvement "No input sources specified." Minor improvement: Check sources Feb 14, 2018
Json::Value const& sources = _input["sources"];
if (!sources)

if (sources.isArray())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use !sources.isObject() here.

@axic axic dismissed their stale review February 14, 2018 13:15

Change needed.

@aarlt aarlt force-pushed the minor_fix_no_input_sources_specified branch 2 times, most recently from 7d6c2b7 to ee57997 Compare February 14, 2018 19:27
Json::Value const& sources = _input["sources"];
if (!sources)

if (!sources.isObject() && !sources.isNull())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need isNull here?

Is IsObject true when the value is null?

Copy link
Collaborator Author

@aarlt aarlt Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@axic nope.. but null is also not an object.. so if there is no sources object at all, it is also not an object.. !sources.isObject() is also true - that's why I do the additional check here.

however, just in case you didn't noticed: I introduced a slightly different error message here: Sources input is not a JSON object. in contrast to Source input is not a JSON object. - from my point of view its nice nice to distinguish between sources is not a json object, and if items of sources - so individual members of the sources object - source is not a json object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if there is no sources object at all, it is also not an object

Ah, yes that makes sense :)

}
)";
Json::Value result = compile(input);
BOOST_CHECK(containsError(result, "JSONError", "Sources input is not a JSON object."));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Field \"sources\" is not a JSON object (or maybe omit field)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thats better. With quotes it's much more clear. I would omit field.

@axic
Copy link
Contributor

axic commented Feb 16, 2018

Please mention this in the changelog, something along the lines of Standard JSON: catch errors properly when invalid "sources" are passed

@axic
Copy link
Contributor

axic commented Feb 16, 2018

I think these are the last two changes and we're good to go.

- returns error, if "sources" is an array, an empty object or not defined
- Added new test-cases in test/libsolidity/StandardCompiler.cpp
@aarlt aarlt force-pushed the minor_fix_no_input_sources_specified branch from ee57997 to 1d4547a Compare February 16, 2018 17:50
@chriseth chriseth merged commit 839acaf into argotorg:develop Feb 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants