From aaf58a8c4e802b1c3c4098066e0788e55600660a Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 25 Nov 2016 13:13:47 +0100 Subject: test: add a test case converting an invalid UTF-8 into a string --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 6dc7ac8c..6181a8a9 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2038,6 +2038,16 @@ BOOST_AUTO_TEST_CASE(string) BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); } +BOOST_AUTO_TEST_CASE(invalid_utf8) +{ + char const* sourceCode = R"( + contract C { + string s = "\xa0\x00"; + } + )"; + CHECK_ERROR(sourceCode, TypeError, "Invalid UTF-8"); +} + BOOST_AUTO_TEST_CASE(string_index) { char const* sourceCode = R"( -- cgit From e136ec87041cce9d8d472e45f4dfbed9a8d02469 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 25 Nov 2016 13:36:06 +0100 Subject: ast: string literals that are not valid UTF are not convertible to strings --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 6181a8a9..cc4da61b 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2045,7 +2045,7 @@ BOOST_AUTO_TEST_CASE(invalid_utf8) string s = "\xa0\x00"; } )"; - CHECK_ERROR(sourceCode, TypeError, "Invalid UTF-8"); + CHECK_ERROR(sourceCode, TypeError, "invalid UTF-8"); } BOOST_AUTO_TEST_CASE(string_index) -- cgit From df5d5edd1b7cb2e9f26d3a2491442185e0ffc17a Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 25 Nov 2016 13:54:13 +0100 Subject: test: add a test about explicitly converting a string literal to string --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index cc4da61b..7a132068 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2038,7 +2038,7 @@ BOOST_AUTO_TEST_CASE(string) BOOST_CHECK_NO_THROW(parseAndAnalyse(sourceCode)); } -BOOST_AUTO_TEST_CASE(invalid_utf8) +BOOST_AUTO_TEST_CASE(invalid_utf8_implicit) { char const* sourceCode = R"( contract C { @@ -2048,6 +2048,16 @@ BOOST_AUTO_TEST_CASE(invalid_utf8) CHECK_ERROR(sourceCode, TypeError, "invalid UTF-8"); } +BOOST_AUTO_TEST_CASE(invalid_utf8_explicit) +{ + char const* sourceCode = R"( + contract C { + string s = string("\xa0\x00"); + } + )"; + CHECK_ERROR(sourceCode, TypeError, "Explicit type conversion not allowed"); +} + BOOST_AUTO_TEST_CASE(string_index) { char const* sourceCode = R"( -- cgit