Skip to content

JSC fix utf8 string creation#140

Draft
CedricGuillemet wants to merge 5 commits intoBabylonJS:mainfrom
CedricGuillemet:JSCUTF8
Draft

JSC fix utf8 string creation#140
CedricGuillemet wants to merge 5 commits intoBabylonJS:mainfrom
CedricGuillemet:JSCUTF8

Conversation

@CedricGuillemet
Copy link
Contributor

@CedricGuillemet CedricGuillemet commented Feb 27, 2026

Fix range error caused by bytes sequence considered invalid. Also, this api was deprecated since c++17.

Copilot AI review requested due to automatic review settings February 27, 2026 15:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request attempts to fix a range error caused by invalid byte sequences in UTF-8 string creation by replacing the deprecated std::wstring_convert and std::codecvt_utf8_utf16 approach with a simpler implementation using JSStringCreateWithUTF8CString directly. The change removes the UTF-8 to UTF-16 conversion path and instead creates a null-terminated copy of the input string.

Changes:

  • Removed <locale> and <codecvt> includes
  • Replaced UTF-8 to UTF-16 conversion with direct UTF-8 string creation
  • Added comments explaining the rationale for avoiding deprecated APIs

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

Comment on lines 112 to 113
}

Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

The new implementation will incorrectly truncate strings that contain embedded null bytes. When a length is specified, the std::string constructor correctly includes all bytes (including embedded nulls), but JSStringCreateWithUTF8CString treats the input as null-terminated and will stop at the first null byte it encounters.

The previous implementation converted to UTF-16 using JSStringCreateWithCharacters which accepts a length parameter and can handle embedded nulls correctly. While the std::wstring_convert approach is deprecated, a better fix would be to implement manual UTF-8 to UTF-16 conversion (similar to the utf16toUTF8 function in V8InspectorUtils.cpp) and continue using JSStringCreateWithCharacters, or use a non-deprecated UTF-8 to UTF-16 conversion library.

Copilot uses AI. Check for mistakes.
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.

2 participants