diff options
author | chriseth <chris@ethereum.org> | 2018-08-08 18:50:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-08 18:50:45 +0800 |
commit | d0863f4994aeefa755cd9589db75e020f1046e72 (patch) | |
tree | cc184a7dcda0bb5a8925b2fc96423ec0ce95cdf2 /libsolidity/ast | |
parent | fd12c718f6fdbac2dbee77738a6ee193b613c84a (diff) | |
parent | 3064bd17bc9393d0761fa65ac64c152d7d02319c (diff) | |
download | dexon-solidity-d0863f4994aeefa755cd9589db75e020f1046e72.tar.gz dexon-solidity-d0863f4994aeefa755cd9589db75e020f1046e72.tar.zst dexon-solidity-d0863f4994aeefa755cd9589db75e020f1046e72.zip |
Merge pull request #4748 from ethereum/validate-identifier
Assert that type identifier contains only valid characters
Diffstat (limited to 'libsolidity/ast')
-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 2b5f2187..565d197a 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -254,6 +254,17 @@ string Type::escapeIdentifier(string const& _identifier) return ret; } +string Type::identifier() const +{ + string ret = escapeIdentifier(richIdentifier()); + solAssert(ret.find_first_of("0123456789") != 0, "Identifier cannot start with a number."); + solAssert( + ret.find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMONPQRSTUVWXYZ_$") == string::npos, + "Identifier contains invalid characters." + ); + return ret; +} + TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type) { solAssert(Token::isElementaryTypeName(_type.token()), diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 09323d05..1fa2b2f5 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -172,7 +172,7 @@ public: /// only if they have the same identifier. /// The identifier should start with "t_". /// Will not contain any character which would be invalid as an identifier. - std::string identifier() const { return escapeIdentifier(richIdentifier()); } + std::string identifier() const; /// More complex identifier strings use "parentheses", where $_ is interpreted as as /// "opening parenthesis", _$ as "closing parenthesis", _$_ as "comma" and any $ that |