Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ extension TwoWaySearcher: CollectionSearcher {
searched.formIndex(before: &lIndex)

if pattern[i] != searched[lIndex] {
searched.formIndex(&state.criticalIndex, offsetBy: period)
_ = searched.formIndex(
&state.criticalIndex,
offsetBy: period,
limitedBy: searched.endIndex)
if periodIsExact { state.memory = (pattern.count - period, end) }
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/RegexTests/AlgorithmsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ class AlgorithmTests: XCTestCase {
expectRanges("ababacabababa", "abababa", [6..<13])
expectRanges("ababacabababa", "aba", [0..<3, 6..<9, 10..<13])
}

// rdar://105154010
func testFirstRangeMissingCrash() {
let str = "%2$@ %#@AROUND_TIME@"
let target = "%@"
XCTAssertNil(str.firstRange(of: target))
XCTAssertNil(str.dropFirst().dropLast().firstRange(of: target))
XCTAssertNil(str.dropFirst().dropLast().firstRange(of: target[...]))
XCTAssertNil(str.firstRange(of: target[...]))
}

func testRegexSplit() {
func expectSplit(
Expand Down