diff options
author | chriseth <chris@ethereum.org> | 2016-08-10 22:31:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-10 22:31:27 +0800 |
commit | fc60839105ee7389bdbf98c6946e4d386b0137ea (patch) | |
tree | 83cb55a469bb76e404c5fd69a2af608a6455f014 /libsolidity | |
parent | cacc3b6bca65b93bb9315bd1b9e42bebec6ed58b (diff) | |
parent | 5d9347f0225d62c51fc4a8a846eaf0468c3077b9 (diff) | |
download | dexon-solidity-fc60839105ee7389bdbf98c6946e4d386b0137ea.tar dexon-solidity-fc60839105ee7389bdbf98c6946e4d386b0137ea.tar.gz dexon-solidity-fc60839105ee7389bdbf98c6946e4d386b0137ea.tar.bz2 dexon-solidity-fc60839105ee7389bdbf98c6946e4d386b0137ea.tar.lz dexon-solidity-fc60839105ee7389bdbf98c6946e4d386b0137ea.tar.xz dexon-solidity-fc60839105ee7389bdbf98c6946e4d386b0137ea.tar.zst dexon-solidity-fc60839105ee7389bdbf98c6946e4d386b0137ea.zip |
Merge pull request #826 from axic/utf8-check
AST printer: do not output invalid UTF8 sequences
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/ast/Types.cpp | 11 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 5630743b..28f7e1b7 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -26,6 +26,7 @@ #include <libdevcore/CommonIO.h> #include <libdevcore/CommonData.h> #include <libdevcore/SHA3.h> +#include <libdevcore/UTF8.h> #include <libsolidity/interface/Utils.h> #include <libsolidity/ast/AST.h> @@ -852,6 +853,16 @@ bool StringLiteralType::operator==(const Type& _other) const return m_value == dynamic_cast<StringLiteralType const&>(_other).m_value; } +std::string StringLiteralType::toString(bool) const +{ + size_t invalidSequence; + + if (!dev::validate(m_value, invalidSequence)) + return "literal_string (contains invalid UTF-8 sequence at position " + dev::toString(invalidSequence) + ")"; + + return "literal_string \"" + m_value + "\""; +} + TypePointer StringLiteralType::mobileType() const { return make_shared<ArrayType>(DataLocation::Memory, true); diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 1ee762e5..1282e5d8 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -419,7 +419,7 @@ public: virtual bool canLiveOutsideStorage() const override { return false; } virtual unsigned sizeOnStack() const override { return 0; } - virtual std::string toString(bool) const override { return "literal_string \"" + m_value + "\""; } + virtual std::string toString(bool) const override; virtual TypePointer mobileType() const override; std::string const& value() const { return m_value; } |