mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #4748 from ethereum/validate-identifier
Assert that type identifier contains only valid characters
This commit is contained in:
commit
d0863f4994
@ -108,7 +108,7 @@ Grammar::
|
|||||||
'break' | 'continue'
|
'break' | 'continue'
|
||||||
FunctionCall =
|
FunctionCall =
|
||||||
Identifier '(' ( Expression ( ',' Expression )* )? ')'
|
Identifier '(' ( Expression ( ',' Expression )* )? ')'
|
||||||
Identifier = [a-zA-Z_$] [a-zA-Z_0-9]*
|
Identifier = [a-zA-Z_$] [a-zA-Z_$0-9]*
|
||||||
IdentifierList = Identifier ( ',' Identifier)*
|
IdentifierList = Identifier ( ',' Identifier)*
|
||||||
TypeName = Identifier | BuiltinTypeName
|
TypeName = Identifier | BuiltinTypeName
|
||||||
BuiltinTypeName = 'bool' | [us] ( '8' | '32' | '64' | '128' | '256' )
|
BuiltinTypeName = 'bool' | [us] ( '8' | '32' | '64' | '128' | '256' )
|
||||||
|
@ -254,6 +254,17 @@ string Type::escapeIdentifier(string const& _identifier)
|
|||||||
return ret;
|
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)
|
TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type)
|
||||||
{
|
{
|
||||||
solAssert(Token::isElementaryTypeName(_type.token()),
|
solAssert(Token::isElementaryTypeName(_type.token()),
|
||||||
|
@ -172,7 +172,7 @@ public:
|
|||||||
/// only if they have the same identifier.
|
/// only if they have the same identifier.
|
||||||
/// The identifier should start with "t_".
|
/// The identifier should start with "t_".
|
||||||
/// Will not contain any character which would be invalid as an identifier.
|
/// 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
|
/// More complex identifier strings use "parentheses", where $_ is interpreted as as
|
||||||
/// "opening parenthesis", _$ as "closing parenthesis", _$_ as "comma" and any $ that
|
/// "opening parenthesis", _$ as "closing parenthesis", _$_ as "comma" and any $ that
|
||||||
|
Loading…
Reference in New Issue
Block a user