Skip to content

Commit c5212e0

Browse files
Merge pull request #601 from rctcwyvrn/5.7-empty-quoted-literal
[5.7] Don't assume quoted literals are non-empty during bytecodegen
2 parents 3c9a2e2 + ab4dded commit c5212e0

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
@@ -109,7 +109,7 @@ fileprivate extension Compiler.ByteCodeGen {
109109
}
110110

111111
// Fast path for eliding boundary checks for an all ascii quoted literal
112-
if optimizationsEnabled && s.allSatisfy(\.isASCII) {
112+
if optimizationsEnabled && s.allSatisfy(\.isASCII) && !s.isEmpty {
113113
let lastIdx = s.unicodeScalars.indices.last!
114114
for idx in s.unicodeScalars.indices {
115115
let boundaryCheck = idx == lastIdx

Tests/RegexTests/MatchTests.swift

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

24662466
// case insensitive tests
24672467
firstMatchTest(#"(?i)abc\u{301}d"#, input: "AbC\u{301}d", match: "AbC\u{301}d", semanticLevel: .unicodeScalar)
2468+
2469+
// check that we don't crash on empty strings
2470+
firstMatchTest(#"\Q\E"#, input: "", match: "")
24682471
}
24692472

24702473
func testCase() {

0 commit comments

Comments
 (0)