Skip to content

Commit afbe222

Browse files
committed
Fix an infinite loop if a conflict marker is found but it's not at the start of a new line
rdar://137746823
1 parent 1cd3534 commit afbe222

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,6 +2448,7 @@ extension Lexer.Cursor {
24482448

24492449
// Must occur at start of line.
24502450
guard restOfBuffer.previous == "\n" || restOfBuffer.previous == "\r" else {
2451+
_ = restOfBuffer.advance()
24512452
continue
24522453
}
24532454

Tests/SwiftParserTest/LexerTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,4 +1706,19 @@ class LexerTests: ParserTestCase {
17061706
]
17071707
)
17081708
}
1709+
1710+
func testConflictMarkerNotAtStartOfLine() {
1711+
assertLexemes(
1712+
#"""
1713+
<<<<<<< a
1714+
>>>>>>> a
1715+
"""#,
1716+
lexemes: [
1717+
LexemeSpec(.binaryOperator, text: "<<<<<<<", trailing: " "),
1718+
LexemeSpec(.identifier, text: "a"),
1719+
LexemeSpec(.binaryOperator, leading: "\n ", text: ">>>>>>>", trailing: " ", flags: [.isAtStartOfLine]),
1720+
LexemeSpec(.identifier, text: "a"),
1721+
]
1722+
)
1723+
}
17091724
}

0 commit comments

Comments
 (0)