Skip to content

fix(tokenize): strip backslash and all declared punctuation from words - #2385

Open
rohitsux wants to merge 1 commit into
livekit:mainfrom
rohitsux:fix/word-tokenizer-punctuation
Open

fix(tokenize): strip backslash and all declared punctuation from words#2385
rohitsux wants to merge 1 commit into
livekit:mainfrom
rohitsux:fix/word-tokenizer-punctuation

Conversation

@rohitsux

Copy link
Copy Markdown

What

splitWords (the basic word tokenizer's punctuation stripper) builds its filter by concatenating PUNCTUATIONS into a regex character class: new RegExp([${PUNCTUATIONS.join('')}], 'g'). Because the list contains both \ and ], the joined class contains the fragment [\], where \] is parsed as an escaped literal ] — so the backslash is consumed as an escape and is never a class member. Backslash (a declared punctuation) is therefore never stripped when ignorePunctuation is on (the default). The adjacent ,-. also silently forms a character range.

Fix

Strip by Set membership instead of a regex built from data — removes exactly the declared characters (backslash included) and eliminates the escaping/range fragility. splitWords' signature and behavior are otherwise unchanged.

Test

Adds a regression test in tokenizer.test.ts: splitWords('c\\d', true) now yields [['cd', 0, 3]] (was [['c\\d', 0, 3]]), and confirms ignorePunctuation: false still preserves it. Full tokenizer suite green; typecheck, lint, and prettier clean.

splitWords built its filter by joining PUNCTUATIONS into a regex character
class. Because the list contains both `\` and `]`, the joined class held the
fragment `[\]`, where `\]` is an escaped literal `]` — so the backslash was
consumed as an escape and never a class member, and was never stripped when
ignorePunctuation is on. Strip by Set membership instead, removing exactly the
declared characters and eliminating the escaping/range fragility.
@rohitsux
rohitsux requested a review from a team as a code owner August 31, 2026 06:49
@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b579a6f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 39 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-anthropic Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-azure Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-did Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-krisp Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-protoface Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

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

@CLAassistant

CLAassistant commented Aug 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants