File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
Sources/_StringProcessing Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -117,8 +117,15 @@ extension DSLTree.Atom {
117117
118118 case . any:
119119 // FIXME: Should this be a total ordering?
120- fatalError (
121- " unreachable: emitAny() should be called isntead " )
120+ if opts. semanticLevel == . graphemeCluster {
121+ return { input, bounds in
122+ input. index ( after: bounds. lowerBound)
123+ }
124+ } else {
125+ return consumeScalar { _ in
126+ true
127+ }
128+ }
122129
123130 case . assertion:
124131 // TODO: We could handle, should this be total?
Original file line number Diff line number Diff line change @@ -1231,6 +1231,29 @@ class RegexDSLTests: XCTestCase {
12311231 }
12321232 }
12331233 }
1234+
1235+ // rdar://96280236
1236+ func testCharacterClassAnyCrash( ) {
1237+ let regex = Regex {
1238+ " { "
1239+ Capture {
1240+ OneOrMore {
1241+ CharacterClass . any. subtracting ( . anyOf( " } " ) )
1242+ }
1243+ }
1244+ " } "
1245+ }
1246+
1247+ func replace( _ template: String ) throws -> String {
1248+ var b = template
1249+ while let result = try regex. firstMatch ( in: b) {
1250+ b. replaceSubrange ( result. range, with: " foo " )
1251+ }
1252+ return b
1253+ }
1254+
1255+ XCTAssertEqual ( try replace ( " {bar} " ) , " foo " )
1256+ }
12341257}
12351258
12361259extension Unicode . Scalar {
You can’t perform that action at this time.
0 commit comments