mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Merge pull request #995 from chriseth/fixutf8astjson
Do not emit non-utf8 strings for ast json.
This commit is contained in:
		
						commit
						171c74843b
					
				| @ -22,6 +22,7 @@ | ||||
| 
 | ||||
| #include <libsolidity/ast/ASTJsonConverter.h> | ||||
| #include <boost/algorithm/string/join.hpp> | ||||
| #include <libdevcore/UTF8.h> | ||||
| #include <libsolidity/ast/AST.h> | ||||
| 
 | ||||
| using namespace std; | ||||
| @ -397,9 +398,21 @@ bool ASTJsonConverter::visit(ElementaryTypeNameExpression const& _node) | ||||
| bool ASTJsonConverter::visit(Literal const& _node) | ||||
| { | ||||
| 	char const* tokenString = Token::toString(_node.token()); | ||||
| 	size_t invalidPos = 0; | ||||
| 	Json::Value value{_node.value()}; | ||||
| 	if (!dev::validate(_node.value(), invalidPos)) | ||||
| 		value = Json::nullValue; | ||||
| 	Token::Value subdenomination = Token::Value(_node.subDenomination()); | ||||
| 	addJsonNode(_node, "Literal", { | ||||
| 		make_pair("string", tokenString ? tokenString : Json::Value()), | ||||
| 		make_pair("value", _node.value()), | ||||
| 		make_pair("token", tokenString ? tokenString : Json::Value()), | ||||
| 		make_pair("value", value), | ||||
| 		make_pair("hexvalue", toHex(_node.value())), | ||||
| 		make_pair( | ||||
| 			"subdenomination", | ||||
| 			subdenomination == Token::Illegal ? | ||||
| 			Json::nullValue : | ||||
| 			Json::Value{Token::toString(subdenomination)} | ||||
| 		), | ||||
| 		make_pair("type", type(_node)) | ||||
| 	}); | ||||
| 	return true; | ||||
|  | ||||
| @ -195,6 +195,22 @@ BOOST_AUTO_TEST_CASE(placeholder_statement) | ||||
| 	BOOST_CHECK_EQUAL(placeholder["src"], "26:1:1"); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(non_utf8) | ||||
| { | ||||
| 	CompilerStack c; | ||||
| 	c.addSource("a", "contract C { function f() { var x = hex\"ff\"; } }"); | ||||
| 	c.parse(); | ||||
| 	map<string, unsigned> sourceIndices; | ||||
| 	sourceIndices["a"] = 1; | ||||
| 	Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); | ||||
| 	Json::Value literal = astJson["children"][0]["children"][0]["children"][2]["children"][0]["children"][1]; | ||||
| 	BOOST_CHECK_EQUAL(literal["name"], "Literal"); | ||||
| 	BOOST_CHECK_EQUAL(literal["attributes"]["hexvalue"], "ff"); | ||||
| 	BOOST_CHECK_EQUAL(literal["attributes"]["token"], Json::nullValue); | ||||
| 	BOOST_CHECK_EQUAL(literal["attributes"]["value"], Json::nullValue); | ||||
| 	BOOST_CHECK(literal["attributes"]["type"].asString().find("invalid") != string::npos); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_SUITE_END() | ||||
| 
 | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user