Skip to content

FIX: prevent splitting supplementary Unicode surrogate pairs in objectivePreview - #3890

Merged
Roman Lutz (romanlutz) merged 6 commits into
microsoft:mainfrom
Aadithya-kl:fix-objective-preview-unicode-3870
Nov 6, 2026
Merged

Roman Lutz (romanlutz) merged 6 commits into
microsoft:mainfrom
Aadithya-kl:fix-objective-preview-unicode-3870

Conversation

@Aadithya-kl

@Aadithya-kl Aadithya (Aadithya-kl) commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #3870.

objectivePreview() previously truncated JavaScript strings by UTF-16 code unit. When the truncation boundary fell between the high and low surrogates of a supplementary Unicode character, the resulting preview could contain an unpaired surrogate.

This change moves the truncation boundary back when necessary, preserving valid Unicode characters without changing the behavior of ordinary ASCII strings.

Tests and Documentation

Added five focused Jest regression tests covering:

  • The exact Unicode truncation reproduction.
  • Preservation of complete surrogate pairs.
  • Existing ASCII truncation behavior.
  • Strings within the preview limit.
  • Null and empty objective fallback behavior.

Verification:

  • Focused Jest tests: 5 passed.
  • npm run type-check: passed.
  • npm run build: passed.

No documentation changes were necessary for this presentation-only fix.

AI Assistance

Antigravity assisted with implementation and regression test authoring. The contributor takes responsibility for the submitted changes.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 16:50

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the change to preserve Unicode surrogate pairs in objective previews.

No open issues 🎉

What changed in this PR

Fixes issue #3870 by preventing objective preview truncation from splitting supplementary Unicode surrogate pairs in the scenario run table. The change affects display formatting, not stored objectives.

Changes:

  • Moves the truncation boundary back when it would split a surrogate pair.
  • Adds regression tests for Unicode boundaries, ASCII truncation, unchanged short strings, and fallback text.
File Description
frontend/​src/​components/​AttackResults/​attackAttemptFormatting.ts Preserves surrogate pairs when truncating objective previews.
frontend/​src/​components/​AttackResults/​attackAttemptFormatting.test.ts Tests Unicode boundary handling and existing preview behavior.

Review effort: Balanced

@Aadithya-kl Aadithya (Aadithya-kl) changed the title fix(frontend): prevent splitting supplementary Unicode surrogate pair… FIX: prevent splitting supplementary Unicode surrogate pairs in objectivePreview Nov 3, 2026
@romanlutz Roman Lutz (romanlutz) self-assigned this Nov 5, 2026
@Aadithya-kl

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@Aadithya-kl

Copy link
Copy Markdown
Contributor Author

Hi maintainers!

I've completed the Microsoft CLA requirement.

I noticed that the five GitHub Actions workflows are currently awaiting maintainer approval, and the PR is also waiting for one approving review.

Could someone with write access please approve the initial workflow runs and review the contribution when convenient?

I've verified the focused tests, TypeScript checks and production build locally. Copilot's review also reported no outstanding issues.

Thank you for your time and for reviewing my first contribution to PyRIT!

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the Unicode-safe objective preview truncation change.

No open issues 🎉

Review effort: Balanced

@romanlutz
Roman Lutz (romanlutz) merged commit 45a1bfe into microsoft:main Nov 6, 2026
53 checks passed
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.

Scenario objective previews can split supplementary Unicode during truncation

3 participants