mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Changed error message for for Unicode character in non-unicode string literal
Co-authored-by: Kamil Śliwak <cameel2@gmail.com>
This commit is contained in:
parent
9542e46ea4
commit
c21265f9f8
@ -76,6 +76,7 @@ string to_string(ScannerError _errorCode)
|
|||||||
case ScannerError::IllegalHexDigit: return "Hexadecimal digit missing or invalid.";
|
case ScannerError::IllegalHexDigit: return "Hexadecimal digit missing or invalid.";
|
||||||
case ScannerError::IllegalCommentTerminator: return "Expected multi-line comment-terminator.";
|
case ScannerError::IllegalCommentTerminator: return "Expected multi-line comment-terminator.";
|
||||||
case ScannerError::IllegalEscapeSequence: return "Invalid escape sequence.";
|
case ScannerError::IllegalEscapeSequence: return "Invalid escape sequence.";
|
||||||
|
case ScannerError::UnicodeCharacterInNonUnicodeString: return "Invalid character in string. If you are trying to use Unicode characters, use a unicode\"...\" string literal.";
|
||||||
case ScannerError::IllegalCharacterInString: return "Invalid character in string.";
|
case ScannerError::IllegalCharacterInString: return "Invalid character in string.";
|
||||||
case ScannerError::IllegalStringEndQuote: return "Expected string end-quote.";
|
case ScannerError::IllegalStringEndQuote: return "Expected string end-quote.";
|
||||||
case ScannerError::IllegalNumberSeparator: return "Invalid use of number separator '_'.";
|
case ScannerError::IllegalNumberSeparator: return "Invalid use of number separator '_'.";
|
||||||
@ -844,7 +845,11 @@ Token Scanner::scanString(bool const _isUnicode)
|
|||||||
// We are using a manual range and not isprint() to avoid
|
// We are using a manual range and not isprint() to avoid
|
||||||
// any potential complications with locale.
|
// any potential complications with locale.
|
||||||
if (!_isUnicode && (static_cast<unsigned>(c) <= 0x1f || static_cast<unsigned>(c) >= 0x7f))
|
if (!_isUnicode && (static_cast<unsigned>(c) <= 0x1f || static_cast<unsigned>(c) >= 0x7f))
|
||||||
return setError(ScannerError::IllegalCharacterInString);
|
{
|
||||||
|
if (m_kind == ScannerKind::Yul)
|
||||||
|
return setError(ScannerError::IllegalCharacterInString);
|
||||||
|
return setError(ScannerError::UnicodeCharacterInNonUnicodeString);
|
||||||
|
}
|
||||||
addLiteralChar(c);
|
addLiteralChar(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@ enum class ScannerError
|
|||||||
IllegalHexDigit,
|
IllegalHexDigit,
|
||||||
IllegalCommentTerminator,
|
IllegalCommentTerminator,
|
||||||
IllegalEscapeSequence,
|
IllegalEscapeSequence,
|
||||||
|
UnicodeCharacterInNonUnicodeString,
|
||||||
IllegalCharacterInString,
|
IllegalCharacterInString,
|
||||||
IllegalStringEndQuote,
|
IllegalStringEndQuote,
|
||||||
IllegalNumberSeparator,
|
IllegalNumberSeparator,
|
||||||
@ -160,6 +161,8 @@ public:
|
|||||||
/// Called by the parser during FunctionDefinition parsing to clear the current comment
|
/// Called by the parser during FunctionDefinition parsing to clear the current comment
|
||||||
void clearCurrentCommentLiteral() { m_skippedComments[Current].literal.clear(); }
|
void clearCurrentCommentLiteral() { m_skippedComments[Current].literal.clear(); }
|
||||||
|
|
||||||
|
ScannerKind scannerKind() const { return m_kind; }
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
///@{
|
///@{
|
||||||
|
@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(string_nonprintable)
|
|||||||
if (v == '\n' || v == '\v' || v == '\f' || v == '\r')
|
if (v == '\n' || v == '\v' || v == '\f' || v == '\r')
|
||||||
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalStringEndQuote);
|
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalStringEndQuote);
|
||||||
else
|
else
|
||||||
BOOST_CHECK_EQUAL(scanner.currentError(), ScannerError::IllegalCharacterInString);
|
BOOST_CHECK_EQUAL(scanner.currentError(),ScannerError::UnicodeCharacterInNonUnicodeString);
|
||||||
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "");
|
BOOST_CHECK_EQUAL(scanner.currentLiteral(), "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
contract test {
|
||||||
|
function f() public pure returns (string memory) {
|
||||||
|
return ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 8936: (86-88): Invalid character in string. If you are trying to use Unicode characters, use a unicode"..." string literal.
|
@ -4,4 +4,4 @@ contract test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// ParserError 8936: (86-88): Invalid character in string.
|
// ParserError 8936: (86-88): Invalid character in string. If you are trying to use Unicode characters, use a unicode"..." string literal.
|
||||||
|
Loading…
Reference in New Issue
Block a user