Repository navigation
Conversation
The CHAMELEON regex matches apostrophes (' \u2018 \u2019). When an apostrophe
is encountered, isWordCharacter recursed on the remaining string to check
whether subsequent characters are part of a word. A long sequence of
consecutive quotes caused unbounded recursion leading to a V8 call stack
exhaustion (RangeError: Maximum call stack size exceeded).
Bound the recursion depth when inspecting chameleon characters and ensure
empty characters evaluate to false.
Reported-by: BS.ehlas.cz
🦋 Changeset detectedLatest commit: 733eeb8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
dylans
reviewed
Nov 11, 2026
| // Chameleons count as word characters as long as they're in a word, so | ||
| // recurse to see if the next one is a word character or not. | ||
| if (CHAMELEON.test(char)) { | ||
| if (depth > 0 || !remaining) { |
Collaborator
There was a problem hiding this comment.
- this changes word results, not just the overflow case
getWordDistance("'hi'")goes from 4 to 3, a quote at the end of the text no longer joins the wordgetWordBounds("''a", 0)goes from[0, 3]to[0, 0], the second quote now stops the lookaheadEditor.positionsword steps andEditor.wordboth read these, so word delete and word moves change near quotes- I compared main and this branch over every string up to 6 chars of
a ' ’ space ., about 28k results differ - a loop that skips the quotes keeps main's results exactly (0 differences on 1.2M cases) and has no recursion:
while (CHAMELEON.test(char)) {
const charDist = getCharacterDistance(remaining, isRTL)
;[char, remaining] = splitByCharacterDistance(remaining, charDist, isRTL)
}
return !SPACE.test(char) && !PUNCTUATION.test(char)- that also handles the 15000 quote test, and
depthand the!charcheck can go
This branch has not been deployed
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.
Description
When encountering a chameleon character (e.g.
',\u2018,\u2019),isWordCharacterinpackages/slate/src/utils/string.tsrecursively inspected following characters to determine if they form part of a word. A long sequence of consecutive quote characters caused unbounded recursion leading to a V8 call stack overflow (RangeError: Maximum call stack size exceeded).This pull request bounds the recursion depth when checking consecutive chameleon characters and ensures empty character inputs evaluate to
false.Issue
N/A
Example
Context
Apostrophes inside words (such as contractions) are isolated single characters between word letters. Multiple consecutive quotation characters do not form word-internal joiners under standard Unicode word boundary rules (UAX #29). Limiting the lookahead recursion depth for chameleon sequences prevents stack exhaustion while preserving word-distance behavior for legitimate words.
Checks
yarn test.yarn lint. (Fix errors withyarn fix.)yarn start.)yarn changeset add.)