mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove the \b, \f, \v escape sequences from the Scanner
This commit is contained in:
parent
933f4db798
commit
66ee3ec533
@ -20,6 +20,7 @@ Breaking Changes:
|
|||||||
* Type System: Declarations with the name ``this``, ``super`` and ``_`` are disallowed, with the exception of public functions and events.
|
* Type System: Declarations with the name ``this``, ``super`` and ``_`` are disallowed, with the exception of public functions and events.
|
||||||
* Type System: Disallow ``type(super)``.
|
* Type System: Disallow ``type(super)``.
|
||||||
* Command Line Interface: JSON fields `abi`, `devdoc`, `userdoc` and `storage-layout` are now sub-objects rather than strings.
|
* Command Line Interface: JSON fields `abi`, `devdoc`, `userdoc` and `storage-layout` are now sub-objects rather than strings.
|
||||||
|
* Scanner: Remove support for the ``\b``, ``\f``, and ``\v`` escape sequences.
|
||||||
|
|
||||||
Language Features:
|
Language Features:
|
||||||
* Super constructors can now be called using the member notation e.g. ``M.C(123)``.
|
* Super constructors can now be called using the member notation e.g. ``M.C(123)``.
|
||||||
|
@ -88,6 +88,9 @@ New Restrictions
|
|||||||
* Declarations with the name ``this``, ``super`` and ``_`` are disallowed, with the exception of
|
* Declarations with the name ``this``, ``super`` and ``_`` are disallowed, with the exception of
|
||||||
public functions and events.
|
public functions and events.
|
||||||
|
|
||||||
|
* Remove support for the ``\b``, ``\f``, and ``\v`` escape sequences in code.
|
||||||
|
They can still be inserted via hexadecimal escapes, e.g. ``\x08``, ``\x0c``, and ``\x0b``, respectively.
|
||||||
|
|
||||||
Interface Changes
|
Interface Changes
|
||||||
=================
|
=================
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ fragment DoubleQuotedPrintable: [\u0020-\u0021\u0023-\u005B\u005D-\u007E];
|
|||||||
*/
|
*/
|
||||||
fragment EscapeSequence:
|
fragment EscapeSequence:
|
||||||
'\\' (
|
'\\' (
|
||||||
['"\\bfnrtv\n\r]
|
['"\\nrt\n\r]
|
||||||
| 'u' HexCharacter HexCharacter HexCharacter HexCharacter
|
| 'u' HexCharacter HexCharacter HexCharacter HexCharacter
|
||||||
| 'x' HexCharacter HexCharacter
|
| 'x' HexCharacter HexCharacter
|
||||||
);
|
);
|
||||||
|
@ -728,12 +728,6 @@ bool Scanner::scanEscape()
|
|||||||
case '"': // fall through
|
case '"': // fall through
|
||||||
case '\\':
|
case '\\':
|
||||||
break;
|
break;
|
||||||
case 'b':
|
|
||||||
c = '\b';
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
c = '\f';
|
|
||||||
break;
|
|
||||||
case 'n':
|
case 'n':
|
||||||
c = '\n';
|
c = '\n';
|
||||||
break;
|
break;
|
||||||
@ -743,9 +737,6 @@ bool Scanner::scanEscape()
|
|||||||
case 't':
|
case 't':
|
||||||
c = '\t';
|
c = '\t';
|
||||||
break;
|
break;
|
||||||
case 'v':
|
|
||||||
c = '\v';
|
|
||||||
break;
|
|
||||||
case 'u':
|
case 'u':
|
||||||
{
|
{
|
||||||
if (auto const codepoint = scanUnicode(); codepoint.has_value())
|
if (auto const codepoint = scanUnicode(); codepoint.has_value())
|
||||||
|
@ -131,10 +131,29 @@ BOOST_AUTO_TEST_CASE(string_escapes)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(string_escapes_all)
|
BOOST_AUTO_TEST_CASE(string_escapes_all)
|
||||||
{
|
{
|
||||||
Scanner scanner(CharStream(" { \"a\\x61\\b\\f\\n\\r\\t\\v\"", ""));
|
Scanner scanner(CharStream(" { \"a\\x61\\n\\r\\t\"", ""));
|
||||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
|
||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "aa\b\f\n\r\t\v");
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "aa\n\r\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(string_escapes_legal_before_080)
|
||||||
|
{
|
||||||
|
Scanner scanner(CharStream(" { \"a\\b", ""));
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalEscapeSequence);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "");
|
||||||
|
scanner.reset(CharStream(" { \"a\\f", ""));
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalEscapeSequence);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "");
|
||||||
|
scanner.reset(CharStream(" { \"a\\v", ""));
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalEscapeSequence);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(string_escapes_with_zero)
|
BOOST_AUTO_TEST_CASE(string_escapes_with_zero)
|
||||||
|
10
test/libsolidity/semanticTests/strings/string_escapes.sol
Normal file
10
test/libsolidity/semanticTests/strings/string_escapes.sol
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
contract test {
|
||||||
|
function f() public pure returns (bytes32) {
|
||||||
|
bytes32 escapeCharacters = "\t\n\r\'\"\\";
|
||||||
|
return escapeCharacters;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f() -> 0x090a0d27225c0000000000000000000000000000000000000000000000000000
|
@ -0,0 +1,8 @@
|
|||||||
|
contract test {
|
||||||
|
function f() public pure returns (bytes32) {
|
||||||
|
bytes32 escapeCharacters = "\t\b\f";
|
||||||
|
return escapeCharacters;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 8936: (100-105): Invalid escape sequence.
|
@ -1,6 +1,6 @@
|
|||||||
contract test {
|
contract test {
|
||||||
function f() public pure returns (bytes32) {
|
function f() public pure returns (bytes32) {
|
||||||
bytes32 escapeCharacters = "\t\b\n\r\f\'\"\\\b";
|
bytes32 escapeCharacters = "\n\r\'\"\\";
|
||||||
return escapeCharacters;
|
return escapeCharacters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user