Skip to content

Commit 1c8702f

Browse files
authored
Merge pull request #600 from rctcwyvrn/oh-no-i-was-dumb
Don't assume quoted literals are non-empty during bytecodegen
2 parents 68f8845 + fc36828 commit 1c8702f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fileprivate extension Compiler.ByteCodeGen {
115115
}
116116

117117
// Fast path for eliding boundary checks for an all ascii quoted literal
118-
if optimizationsEnabled && s.allSatisfy(\.isASCII) {
118+
if optimizationsEnabled && s.allSatisfy(\.isASCII) && !s.isEmpty {
119119
let lastIdx = s.unicodeScalars.indices.last!
120120
for idx in s.unicodeScalars.indices {
121121
let boundaryCheck = idx == lastIdx

Tests/RegexTests/MatchTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,9 @@ extension RegexTests {
24582458

24592459
// case insensitive tests
24602460
firstMatchTest(#"(?i)abc\u{301}d"#, input: "AbC\u{301}d", match: "AbC\u{301}d", semanticLevel: .unicodeScalar)
2461+
2462+
// check that we don't crash on empty strings
2463+
firstMatchTest(#"\Q\E"#, input: "", match: "")
24612464
}
24622465

24632466
func testCase() {

0 commit comments

Comments
 (0)