Skip to content

Normalize invisible and whitespace characters on copy#88

Merged
jonrohan merged 1 commit into
mainfrom
normalize-invisible-characters
Jun 16, 2026
Merged

Normalize invisible and whitespace characters on copy#88
jonrohan merged 1 commit into
mainfrom
normalize-invisible-characters

Conversation

@jonrohan

Copy link
Copy Markdown
Member

Extends normalizeText() to cover the full range of Unicode characters that render as a space or as nothing, so copied text matches what is shown on screen.

  • Space-separator characters are replaced with a regular ASCII space.
  • Zero-width and invisible format characters are stripped.

Adds tests covering both sets.

Copilot AI review requested due to automatic review settings June 16, 2026 18:02
@jonrohan jonrohan requested a review from a team as a code owner June 16, 2026 18:02
GitHub Advanced Security started work on behalf of jonrohan June 16, 2026 18:02 View session
GitHub Advanced Security finished work on behalf of jonrohan June 16, 2026 18:04
@jonrohan jonrohan merged commit 1feba66 into main Jun 16, 2026
6 checks passed
@jonrohan jonrohan deleted the normalize-invisible-characters branch June 16, 2026 18:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR expands normalizeText() in the clipboard copy pipeline to reduce copy/paste spoofing by converting all Unicode space-separator characters to ASCII spaces and stripping selected invisible/zero-width format characters, with accompanying tests.

Changes:

  • Extend normalizeText() to normalize Unicode space separators to ' ' and strip a set of invisible/zero-width characters.
  • Add tests that iterate through multiple Unicode whitespace and invisible characters to validate clipboard output.
Show a summary per file
File Description
src/clipboard.ts Broadens text normalization for clipboard writes (space separators → ASCII space; some invisible characters stripped).
test/test.js Adds coverage for additional Unicode whitespace normalization and invisible-character stripping behaviors.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread src/clipboard.ts
Comment on lines +14 to +16
return text
.replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' ')
.replace(/[\u200B-\u200D\u2060\uFEFF\u180E]/g, '')
Comment thread test/test.js
Comment on lines +218 to +220
it('strips zero-width and invisible format characters', async function () {
const zeroWidthChars = ['\u200B', '\u200C', '\u200D', '\u2060', '\uFEFF', '\u180E']

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.

3 participants