Skip to content

fix(teams): strip non-printable control characters from message body - #1767

Open
octo-patch wants to merge 1 commit into
airweave-ai:mainfrom
octo-patch:fix/issue-1269-sanitize-teams-message-control-chars
Open

fix(teams): strip non-printable control characters from message body#1767
octo-patch wants to merge 1 commit into
airweave-ai:mainfrom
octo-patch:fix/issue-1269-sanitize-teams-message-control-chars

Conversation

@octo-patch

@octo-patch octo-patch commented Apr 26, 2026

Copy link
Copy Markdown

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:

Could not parse field 'textual_representation' of type string:
The string field value contains illegal code point 0x1B

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 in platform/entities/teams.py that 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 to body_content in TeamsMessageEntity.from_api() before the entity is yielded, so the cleaned text flows through to textual_representation.

Testing

  • Added 11 unit tests in tests/unit/platform/sources/test_teams_entity.py covering:
    • _sanitize_text() helper: None passthrough, plain text, preserved whitespace, ESC/NUL/DEL removal, ANSI escape sequences, empty string
    • TeamsMessageEntity.from_api(): control chars stripped from body, clean body unchanged, name preview free of control chars
  • All 11 tests pass.

Summary 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() so textual_representation stays clean even when users paste ANSI-colored terminal output.

Written for commit bd5a24c. Summary will update on new commits.

…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>

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Sync Failure: Illegal code point 0x1B in TeamsMessageEntity causes Vespa ingestion to fail

1 participant