Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Compiler Features:

Bugfixes:
* NatSpec: Disallow `@return` tag in event documentation.
* Parser: Detect unbalanced Unicode direction override markers (e.g. `U+202E`) in documentation comments (`///` and `/** */`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Parser: Detect unbalanced Unicode direction override markers (e.g. `U+202E`) in documentation comments (`///` and `/** */`)
* Scanner: Detect unbalanced Unicode direction override markers (e.g. `U+202E`) in documentation comments (`///` and `/** */`)

* SMTChecker: Fix incorrect handling of constant operands of unary operations.


Expand Down
13 changes: 11 additions & 2 deletions liblangutil/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ bool Scanner::tryScanEndOfLine()
size_t Scanner::scanSingleLineDocComment()
{
LiteralScope literal(this, LITERAL_TYPE_COMMENT);
size_t const startPosition = m_source.position();
size_t endPosition = m_source.position();

skipWhitespaceExceptUnicodeLinebreak();
Expand Down Expand Up @@ -385,6 +386,9 @@ size_t Scanner::scanSingleLineDocComment()
advance();
}
literal.complete();
ScannerError const unicodeDirectionError = validateBiDiMarkup(m_source, startPosition);
if (unicodeDirectionError != ScannerError::NoError)
m_skippedComments[NextNext].error = unicodeDirectionError;
return endPosition;
}

Expand Down Expand Up @@ -416,6 +420,7 @@ Token Scanner::skipMultiLineComment()
Token Scanner::scanMultiLineDocComment()
{
LiteralScope literal(this, LITERAL_TYPE_COMMENT);
size_t const startPosition = m_source.position();
bool endFound = false;
bool charsAdded = false;

Expand Down Expand Up @@ -464,8 +469,10 @@ Token Scanner::scanMultiLineDocComment()
literal.complete();
if (!endFound)
return setError(ScannerError::IllegalCommentTerminator);
else
return Token::CommentLiteral;
ScannerError const unicodeDirectionError = validateBiDiMarkup(m_source, startPosition);
if (unicodeDirectionError != ScannerError::NoError)
return setError(unicodeDirectionError);
return Token::CommentLiteral;
}

Token Scanner::scanSlash()
Expand All @@ -488,6 +495,8 @@ Token Scanner::scanSlash()
m_skippedComments[NextNext].location.sourceName = m_sourceName;
m_skippedComments[NextNext].token = Token::CommentLiteral;
m_skippedComments[NextNext].location.end = static_cast<int>(scanSingleLineDocComment());
if (m_skippedComments[NextNext].error != ScannerError::NoError)
return setError(m_skippedComments[NextNext].error);
return Token::Whitespace;
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contract C {
function f() public pure
{
// RLO
/** overflow ‮ */
}
}
// ----
// ParserError 8936: (71-90): Mismatching directional override markers in comment or string literal.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contract C {
function f() public pure
{
// PDF
/** underflow ‬ */
}
}
// ----
// ParserError 8936: (71-85): Unicode direction override underflow in comment or string literal.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract C {
function f() public pure
{
// RLO PDF
/** ok ‮‬ */
}
}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contract C {
function f() public pure
{
// RLO
/// overflow ‮
}
}
// ----
// ParserError 8936: (71-92): Mismatching directional override markers in comment or string literal.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
contract C {
function f() public pure
{
// PDF
/// underflow ‬
Comment on lines +4 to +5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a multiline comment test case, for each of these (// and ///) where you open an override on one line and close it on the next?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also /** */

}
}
// ----
// ParserError 8936: (71-85): Unicode direction override underflow in comment or string literal.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract C {
function f() public pure
{
// RLO PDF
/// ok ‮‬
}
}
// ----