Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nbsp is removed from string when submitting form #50539

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/libs/StringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ function removeInvisibleCharacters(value: string): string {

// Remove spaces:
// - \u200B: zero-width space
// - \u00A0: non-breaking space
// - \u2060: word joiner
result = result.replace(/[\u200B\u00A0\u2060]/g, '');

// Temporarily replace all newlines with non-breaking spaces
// It is necessary because the next step removes all newlines because they are in the (Cc) category
result = result.replace(/\n/g, '\u00A0');

// Remove all characters from the 'Other' (C) category except for format characters (Cf)
// because some of them are used for emojis
result = result.replace(/[\p{Cc}\p{Cs}\p{Co}\p{Cn}]/gu, '');

// Replace all non-breaking spaces with newlines
result = result.replace(/\u00A0/g, '\n');
result = result.replace(/[\u200B\u2060]/g, '');

// The control unicode (Cc) regex removes all newlines,
// so we first split the string by newline and rejoin it afterward to retain the original line breaks.
result = result
.split('\n')
.map((part) =>
// Remove all characters from the 'Other' (C) category except for format characters (Cf)
// because some of them are used for emojis
part.replace(/[\p{Cc}\p{Cs}\p{Co}\p{Cn}]/gu, ''),
)
.join('\n');

// Remove characters from the (Cf) category that are not used for emojis
result = result.replace(/[\u200E-\u200F]/g, '');
Expand Down
Loading