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
11 changes: 9 additions & 2 deletions Sources/_StringProcessing/ConsumerInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ extension DSLTree.Atom {

case .any:
// FIXME: Should this be a total ordering?
fatalError(
"unreachable: emitAny() should be called isntead")
if opts.semanticLevel == .graphemeCluster {
return { input, bounds in
input.index(after: bounds.lowerBound)
}
} else {
return consumeScalar { _ in
true
}
}

case .assertion:
// TODO: We could handle, should this be total?
Expand Down
23 changes: 23 additions & 0 deletions Tests/RegexBuilderTests/RegexDSLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,29 @@ class RegexDSLTests: XCTestCase {
}
}
}

// rdar://96280236
func testCharacterClassAnyCrash() {
let regex = Regex {
"{"
Capture {
OneOrMore {
CharacterClass.any.subtracting(.anyOf("}"))
}
}
"}"
}

func replace(_ template: String) throws -> String {
var b = template
while let result = try regex.firstMatch(in: b) {
b.replaceSubrange(result.range, with: "foo")
}
return b
}

XCTAssertEqual(try replace("{bar}"), "foo")
}
}

extension Unicode.Scalar {
Expand Down