Repository navigation
Conversation
`atSimpleBoundary` under `.unicodeScalar` semantics only treated alphabetic scalars and underscore as word characters, so `\b` with `.wordBoundaryKind(.simple)` disagreed with `\w` on digits. Use `Character.isWordCharacter` (letter, digit/number, or underscore) for the scalar path as well. Fixes swiftlang#884
hippi345
marked this pull request as ready for review
October 17, 2026 03:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With
.wordBoundaryKind(.simple)and.matchingSemantics(.unicodeScalar)together,\btreated digits as non-word characters even though\wstill matches them. Either option alone already classified digits as word characters.atSimpleBoundaryin unicode-scalar mode usedisAlphabetic || "_"and omitted digits. It now uses the same word-character predicate as\w/Character.isWordCharacter(letter, digit/number, or underscore).Fixes #884
#901 reports the same bug.
Changes
Sources/_StringProcessing/Unicode/WordBreaking.swift: classify scalars withCharacter.isWordCharacterinstead of alphabetic-or-underscore only.Tests/RegexTests/MatchTests.swift: addtestSimpleWordBoundaryDigitsWithUnicodeScalarSemanticscovering the\btreats digits as non-word characters with .wordBoundaryKind(.simple) and .matchingSemantics(.unicodeScalar) #884 repro (digits at/inside word edges) plus letter and underscore cases.Testing
On unmodified main (test only, no source fix),
swift test --filter testSimpleWordBoundaryDigitsWithUnicodeScalarSemanticsfailed:Those five failures are the #884 cases:
"9"vs9\b,"e9"vs(r|e)9\b,"x5"vsx\b,"5x"vs\bx, and"1pw2"vs\bpwd?\b.After the fix, the same filter passed:
swift test --filter RegexTestsalso passed: 131 XCTest cases in the RegexTests target (including MatchTests and nearby suites), 9 DocumentationTestsRegexTestscases, and 6 Swift Testing cases in OptimizationTests/DSLListTests, 0 failures.This change was prepared with AI assistance and reviewed by the author.