fix(teams): strip non-printable control characters from message body - #1767
Open
octo-patch wants to merge 1 commit into
Open
fix(teams): strip non-printable control characters from message body#1767octo-patch wants to merge 1 commit into
octo-patch wants to merge 1 commit into
Conversation
…airweave-ai#1269) Teams messages can contain raw terminal output or rich-text artifacts with non-printable ASCII control characters (e.g. ESC/\x1b). Vespa and other strict destinations reject documents that include these bytes, causing syncs to fail with "illegal code point" errors. Add `_sanitize_text()` in `platform/entities/teams.py` that strips all control characters in the range \x00-\x1f except for the safe whitespace characters \t, \n, and \r, as well as \x7f (DEL). Apply it to `body_content` in `TeamsMessageEntity.from_api()` so that the sanitized text flows through to `textual_representation` before being indexed. Add unit tests for the sanitizer and the entity factory method. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
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.
Fixes #1269
Problem
Microsoft Teams messages can contain non-printable ASCII control characters such as ESC (
\x1b) when users paste terminal output, ANSI colour codes, or certain rich-text artifacts. Vespa (and other strict destinations) reject these bytes with the error:This causes the entire sync to fail during the ingestion stage with zero entities synced from the affected message onward.
Solution
Add a
_sanitize_text()helper inplatform/entities/teams.pythat removes all non-printable control characters in the range\x00–\x1f(excluding the common whitespace characters\t,\n,\r) and\x7f(DEL). The sanitizer is applied tobody_contentinTeamsMessageEntity.from_api()before the entity is yielded, so the cleaned text flows through totextual_representation.Testing
tests/unit/platform/sources/test_teams_entity.pycovering:_sanitize_text()helper:Nonepassthrough, plain text, preserved whitespace, ESC/NUL/DEL removal, ANSI escape sequences, empty stringTeamsMessageEntity.from_api(): control chars stripped from body, clean body unchanged, name preview free of control charsSummary by cubic
Sanitizes Microsoft Teams message bodies by stripping non-printable control characters to prevent Vespa ingestion failures and sync stoppages. The sanitizer runs in
TeamsMessageEntity.from_api()sotextual_representationstays clean even when users paste ANSI-colored terminal output.Written for commit bd5a24c. Summary will update on new commits.