Replace String.fromCharCode() with String.fromCodePoint() for Unicode safety#34
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Replace String.fromCharCode() with String.fromCodePoint() for Unicode safety#34sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZnd_k0U9LJ6Ep7RioAG for typescript:S7758 rule - AZnd_k0U9LJ6Ep7RioAA for typescript:S7758 rule - AZnd_k0U9LJ6Ep7RioAB for typescript:S7758 rule - AZnd_k0U9LJ6Ep7RioAD for typescript:S7758 rule - AZnd_k0U9LJ6Ep7RioAE for typescript:S7758 rule Generated by SonarQube Agent (task: 512dddeb-dbb2-4973-ba30-dd2eb278c646)
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.
Updated the handleSpecialCharacters module to use String.fromCodePoint() instead of String.fromCharCode() for generating special characters like carriage returns, tabs, and backslashes. String.fromCodePoint() is the modern Unicode-safe alternative that properly handles the full range of Unicode code points including characters requiring surrogate pairs.
View Project in SonarCloud
Fixed Issues
typescript:S7758 - Prefer `String.fromCodePoint()` over `String.fromCharCode()`. • MINOR • View issue
Location:
src/handleSpecialCharacters/index.ts:13Why is this an issue?
JavaScript strings use UTF-16 encoding internally. Some Unicode characters, like emojis and certain international characters, require two 16-bit code units (called surrogate pairs) to represent a single character.
What changed
This hunk replaces four occurrences of
String.fromCharCode()withString.fromCodePoint()in theremoveSpecialCharactersfunction. Specifically, it fixes: theString.fromCharCode(13)call on line 13 (replacing carriage return generation), theString.fromCharCode(9)call on line 14 (replacing tab generation), and bothString.fromCharCode(92)andString.fromCharCode(92, 92)calls on line 15 (replacing backslash generation). TheString.fromCharCode(10)on line 12 is also replaced though it wasn't flagged. UsingString.fromCodePoint()is the modern, Unicode-safe alternative that properly handles surrogate pairs for characters outside the Basic Multilingual Plane.typescript:S7758 - Prefer `String.fromCodePoint()` over `String.fromCharCode()`. • MINOR • View issue
Location:
src/handleSpecialCharacters/index.ts:14Why is this an issue?
JavaScript strings use UTF-16 encoding internally. Some Unicode characters, like emojis and certain international characters, require two 16-bit code units (called surrogate pairs) to represent a single character.
What changed
This hunk replaces four occurrences of
String.fromCharCode()withString.fromCodePoint()in theremoveSpecialCharactersfunction. Specifically, it fixes: theString.fromCharCode(13)call on line 13 (replacing carriage return generation), theString.fromCharCode(9)call on line 14 (replacing tab generation), and bothString.fromCharCode(92)andString.fromCharCode(92, 92)calls on line 15 (replacing backslash generation). TheString.fromCharCode(10)on line 12 is also replaced though it wasn't flagged. UsingString.fromCodePoint()is the modern, Unicode-safe alternative that properly handles surrogate pairs for characters outside the Basic Multilingual Plane.typescript:S7758 - Prefer `String.fromCodePoint()` over `String.fromCharCode()`. • MINOR • View issue
Location:
src/handleSpecialCharacters/index.ts:31Why is this an issue?
JavaScript strings use UTF-16 encoding internally. Some Unicode characters, like emojis and certain international characters, require two 16-bit code units (called surrogate pairs) to represent a single character.
What changed
This hunk replaces two occurrences of
String.fromCharCode()withString.fromCodePoint()in theinsertSpecialCharactersfunction. Specifically, it fixes theString.fromCharCode(9)call on line 31 and theString.fromCharCode(92, 92)/String.fromCharCode(92)calls on line 32. UsingString.fromCodePoint()is the preferred modern method that correctly handles full Unicode code points including characters that require surrogate pairs.typescript:S7758 - Prefer `String.fromCodePoint()` over `String.fromCharCode()`. • MINOR • View issue
Location:
src/handleSpecialCharacters/index.ts:15Why is this an issue?
JavaScript strings use UTF-16 encoding internally. Some Unicode characters, like emojis and certain international characters, require two 16-bit code units (called surrogate pairs) to represent a single character.
What changed
This hunk replaces four occurrences of
String.fromCharCode()withString.fromCodePoint()in theremoveSpecialCharactersfunction. Specifically, it fixes: theString.fromCharCode(13)call on line 13 (replacing carriage return generation), theString.fromCharCode(9)call on line 14 (replacing tab generation), and bothString.fromCharCode(92)andString.fromCharCode(92, 92)calls on line 15 (replacing backslash generation). TheString.fromCharCode(10)on line 12 is also replaced though it wasn't flagged. UsingString.fromCodePoint()is the modern, Unicode-safe alternative that properly handles surrogate pairs for characters outside the Basic Multilingual Plane.typescript:S7758 - Prefer `String.fromCodePoint()` over `String.fromCharCode()`. • MINOR • View issue
Location:
src/handleSpecialCharacters/index.ts:15Why is this an issue?
JavaScript strings use UTF-16 encoding internally. Some Unicode characters, like emojis and certain international characters, require two 16-bit code units (called surrogate pairs) to represent a single character.
What changed
This hunk replaces four occurrences of
String.fromCharCode()withString.fromCodePoint()in theremoveSpecialCharactersfunction. Specifically, it fixes: theString.fromCharCode(13)call on line 13 (replacing carriage return generation), theString.fromCharCode(9)call on line 14 (replacing tab generation), and bothString.fromCharCode(92)andString.fromCharCode(92, 92)calls on line 15 (replacing backslash generation). TheString.fromCharCode(10)on line 12 is also replaced though it wasn't flagged. UsingString.fromCodePoint()is the modern, Unicode-safe alternative that properly handles surrogate pairs for characters outside the Basic Multilingual Plane.SonarQube Remediation Agent uses AI. Check for mistakes.