Skip to content

Commit 33b0b4c

Browse files
committed
Fix character class trivia matching
Rather than matching and not advancing the input, we should always return `nil` to never match against the trivia.
1 parent 935d748 commit 33b0b4c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,8 @@ extension DSLTree.CustomCharacterClass.Member {
287287
}
288288
case .trivia:
289289
// TODO: Should probably strip this earlier...
290-
return { _, bounds in
291-
return bounds.lowerBound
292-
}
290+
return { _, _ in nil }
293291
}
294-
295292
}
296293
}
297294

Tests/RegexTests/MatchTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,16 @@ extension RegexTests {
12081208
("CaFe", true),
12091209
("EfAc", true))
12101210
}
1211+
1212+
func testNonSemanticWhitespace() {
1213+
firstMatchTest(#" \t "#, input: " \t ", match: " \t ")
1214+
firstMatchTest(#"(?xx) \t "#, input: " \t ", match: "\t")
1215+
1216+
firstMatchTest(#"[ \t]+"#, input: " \t ", match: " \t ")
1217+
firstMatchTest(#"(?xx)[ \t]+"#, input: " \t ", match: "\t")
1218+
firstMatchTest(#"(?xx)[ \t]+"#, input: " \t\t ", match: "\t\t")
1219+
firstMatchTest(#"(?xx)[ \t]+"#, input: " \t \t", match: "\t")
1220+
}
12111221

12121222
func testASCIIClasses() {
12131223
// 'D' ASCII-only digits

0 commit comments

Comments
 (0)