From 2f91781a809eb85978a56bef6758a9a3cf2fa773 Mon Sep 17 00:00:00 2001 From: Mudit Gupta Date: Wed, 23 Jan 2019 10:22:27 +0530 Subject: [PATCH] useLiteralContent data validation Squashed commit of the following: commit bbceee6997c1b951eb6054f7d5b7560fe1773690 Author: Mudit Gupta Date: Tue Jan 22 23:27:49 2019 +0530 Removed extra check commit 4f7c3cc58e94836b1dddcc5f2938da14adad6252 Author: Mudit Gupta Date: Tue Jan 22 17:51:05 2019 +0530 Updated test error message commit 5da45f2a23840e7bb1978853e1c184faec65b3e0 Author: Mudit Gupta Date: Tue Jan 22 17:46:09 2019 +0530 Renamed test commit e661418deac25f31c49091be3c80244f566fc14c Author: Leonardo Date: Tue Jan 22 17:41:56 2019 +0530 Update libsolidity/interface/StandardCompiler.cpp Co-Authored-By: maxsam4 commit d289b4dc1956ab736aada613e810cf2e2d124d4d Author: Mudit Gupta Date: Tue Jan 22 17:29:40 2019 +0530 changed style commit 5a7cf08db3027d75081d2e698dd51b807bef5abb Author: Mudit Gupta Date: Tue Jan 22 17:20:37 2019 +0530 Added test case for missing useLiteralContent commit 6e866c46aa92d6a89f2b341bd717c3886946f3ff Author: Mudit Gupta Date: Tue Jan 22 17:09:30 2019 +0530 input check for useLiteralContent --- libsolidity/interface/StandardCompiler.cpp | 2 ++ .../exit | 1 + .../input.json | 19 +++++++++++++++++ .../output.json | 1 + .../exit | 1 + .../input.json | 21 +++++++++++++++++++ .../output.json | 1 + 7 files changed, 46 insertions(+) create mode 100644 test/cmdlineTests/standard_missing_key_useLiteralContent/exit create mode 100644 test/cmdlineTests/standard_missing_key_useLiteralContent/input.json create mode 100644 test/cmdlineTests/standard_missing_key_useLiteralContent/output.json create mode 100644 test/cmdlineTests/standard_wrong_type_useLiteralContent/exit create mode 100644 test/cmdlineTests/standard_wrong_type_useLiteralContent/input.json create mode 100644 test/cmdlineTests/standard_wrong_type_useLiteralContent/output.json diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 137a4439a..606e858c6 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -298,6 +298,8 @@ boost::optional checkOptimizerKeys(Json::Value const& _input) boost::optional checkMetadataKeys(Json::Value const& _input) { + if (_input.isObject() && _input.isMember("useLiteralContent") && !_input["useLiteralContent"].isBool()) + return formatFatalError("JSONError", "\"settings.metadata.useLiteralContent\" must be Boolean"); static set keys{"useLiteralContent"}; return checkKeys(_input, keys, "settings.metadata"); } diff --git a/test/cmdlineTests/standard_missing_key_useLiteralContent/exit b/test/cmdlineTests/standard_missing_key_useLiteralContent/exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/test/cmdlineTests/standard_missing_key_useLiteralContent/exit @@ -0,0 +1 @@ +0 diff --git a/test/cmdlineTests/standard_missing_key_useLiteralContent/input.json b/test/cmdlineTests/standard_missing_key_useLiteralContent/input.json new file mode 100644 index 000000000..8627a282a --- /dev/null +++ b/test/cmdlineTests/standard_missing_key_useLiteralContent/input.json @@ -0,0 +1,19 @@ +{ + "language": "Solidity", + "sources": + { + "A": + { + "content": "pragma solidity >=0.0; contract C { function f() public pure {} }" + } + }, + "settings": + { + "optimizer": { + "enabled": true, + "runs": 200 + }, + "evmVersion": "byzantium", + "metadata": {} + } +} diff --git a/test/cmdlineTests/standard_missing_key_useLiteralContent/output.json b/test/cmdlineTests/standard_missing_key_useLiteralContent/output.json new file mode 100644 index 000000000..14c325725 --- /dev/null +++ b/test/cmdlineTests/standard_missing_key_useLiteralContent/output.json @@ -0,0 +1 @@ +{"sources":{"A":{"id":0}}} \ No newline at end of file diff --git a/test/cmdlineTests/standard_wrong_type_useLiteralContent/exit b/test/cmdlineTests/standard_wrong_type_useLiteralContent/exit new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/test/cmdlineTests/standard_wrong_type_useLiteralContent/exit @@ -0,0 +1 @@ +0 diff --git a/test/cmdlineTests/standard_wrong_type_useLiteralContent/input.json b/test/cmdlineTests/standard_wrong_type_useLiteralContent/input.json new file mode 100644 index 000000000..be4272b6c --- /dev/null +++ b/test/cmdlineTests/standard_wrong_type_useLiteralContent/input.json @@ -0,0 +1,21 @@ +{ + "language": "Solidity", + "sources": + { + "A": + { + "content": "pragma solidity >=0.0; contract C { function f() public pure {} }" + } + }, + "settings": + { + "optimizer": { + "enabled": true, + "runs": 200 + }, + "evmVersion": "byzantium", + "metadata": { + "useLiteralContent": "literalContent" + } + } +} diff --git a/test/cmdlineTests/standard_wrong_type_useLiteralContent/output.json b/test/cmdlineTests/standard_wrong_type_useLiteralContent/output.json new file mode 100644 index 000000000..47eb32ec4 --- /dev/null +++ b/test/cmdlineTests/standard_wrong_type_useLiteralContent/output.json @@ -0,0 +1 @@ +{"errors":[{"component":"general","formattedMessage":"\"settings.metadata.useLiteralContent\" must be Boolean","message":"\"settings.metadata.useLiteralContent\" must be Boolean","severity":"error","type":"JSONError"}]}