Handle edge case when parsing

config-change
Nikhil Parasaram 12 months ago
parent 17740aa9e2
commit 80c3469a91
  1. 2
      mythril/ethereum/util.py
  2. 1
      tests/util_tests.py

@ -156,7 +156,7 @@ def parse_pragma(solidity_code):
max_version = Optional(inequality + version) max_version = Optional(inequality + version)
pragma = Word("pragma") + Word("solidity") + min_version + Optional(max_version) pragma = Word("pragma") + Word("solidity") + min_version + Optional(max_version)
result = pragma.parseString(solidity_code) result = pragma.parseString(solidity_code)
min_inequality = result[2] if result[2] in [">", "<", ">=", "<="] else "" min_inequality = result[2] if result[2] in [">", "<", ">=", "<=", "="] else ""
min_carrot = result[2] if result[2] == "^" else "" min_carrot = result[2] if result[2] == "^" else ""
min_version = result[3] if min_carrot != "" or min_inequality != "" else result[2] min_version = result[3] if min_carrot != "" or min_inequality != "" else result[2]
return { return {

@ -5,6 +5,7 @@ from mythril.ethereum.util import extract_version
test_data = ( test_data = (
("pragma solidity 0.5.0\n", ["0.5.0"]), ("pragma solidity 0.5.0\n", ["0.5.0"]),
("pragma solidity =0.5.0\n", ["0.5.0"]),
("pragma solidity ^0.4.26\n", ["0.4.26"]), ("pragma solidity ^0.4.26\n", ["0.4.26"]),
("pragma solidity ^0.6.3;\n", [f"0.6.{x}" for x in range(3, 13)]), ("pragma solidity ^0.6.3;\n", [f"0.6.{x}" for x in range(3, 13)]),
("pragma solidity ^0.6.3 ;\n", [f"0.6.{x}" for x in range(3, 13)]), ("pragma solidity ^0.6.3 ;\n", [f"0.6.{x}" for x in range(3, 13)]),

Loading…
Cancel
Save