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

[bugfix] Fixed to properly convert multibyte text to juce::String. #1393

Closed

Conversation

COx2
Copy link
Contributor

@COx2 COx2 commented Jun 15, 2024

Summary

This fixes an issue where the implementation of the juce::String::fromUTF8 function incorrectly handles multi-byte character strings.

Details

The current implementation may incorrectly treat parts of multi-byte character strings as invalid characters.
For example, consider the following code:

// Equivalent to --> auto url = juce::URL(juce::File("C:/path/to/日本語"));
auto url = juce::URL(juce::File(juce::CharPointer_UTF8("C:/path/to/\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e")));

// Return is --> file:///C%3A/path/to/%E6%97%A5%E6%9C%AC%E8%AA%9E
juce::Logger::outputDebugString(url.toString(true));

// Output is --> C:\path\to\日本語9E9E9E
juce::Logger::outputDebugString(url.getLocalFile().getFullPathName());

As you can see, the multi-byte characters in the file path are not properly handled, leading to incorrect encoding and data corruption.
With this fix, multi-byte character strings are properly interpreted, and the entire string is correctly decoded.

After fix

With this fix applied, the execution result of the above code will change, and the conversion process from multi-byte character strings (including Japanese characters) to juce::String will work correctly.

// Equivalent to --> auto url = juce::URL(juce::File("C:/path/to/日本語"));
auto url = juce::URL(juce::File(juce::CharPointer_UTF8("C:/path/to/\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e")));

// Return is --> file:///C%3A/path/to/%E6%97%A5%E6%9C%AC%E8%AA%9E
juce::Logger::outputDebugString(url.toString(true));

// Output is --> C:\path\to\日本語
juce::Logger::outputDebugString(url.getLocalFile().getFullPathName());

Related Files

  • juce_String.cpp - Modified the implementation of the fromUTF8 function.

This implementation is equivalent to JUCE 7.
@reuk
Copy link
Member

reuk commented Jun 24, 2024

Thanks for reporting this issue, the suggested fix has been merged here: 131b838

@reuk reuk closed this Jun 24, 2024
@COx2
Copy link
Contributor Author

COx2 commented Jun 25, 2024

Thanks!

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