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

Bug: C++WinRT does not correctly handles Chinese characters using Windows.Foundation.Uri #1424

Closed
HO-COOH opened this issue Jul 8, 2024 · 5 comments

Comments

@HO-COOH
Copy link

HO-COOH commented Jul 8, 2024

Version

2.0.240405.15

Summary

I have a uri with Chinese character and query string that needs to be parsed with Windows.Foundation.Uri. Using C++WinRT, it always returns me an empty result. But equivalent C# code does returns me expected result.

I have tried changing the file encoding to either UTF-8 and UTF-8 BOM, nothing worked.

Reproducible example

With C++WinRT, create a C++WinRT console application:

    winrt::Windows::Foundation::Uri uri{ LR"(myapp://open?file="C:/我.txt")" };
    winrt::Windows::Foundation::WwwFormUrlDecoder parsed{ uri.Query() };
    for (auto entry : parsed)
    {
        std::wcout << entry.Name().data() << L'\t' << entry.Value().data() << L'\n';
    }

With C#, create a UWP project:

            var uri = new Uri("myapp://open?file=\"C:/我.txt\"");
            var parsed = new WwwFormUrlDecoder(uri.Query);
            foreach (var entry in parsed)
            {
                Debug.WriteLine(entry);
            }

Expected behavior

C# result is expected:
image

Actual behavior

C++WinRT result:
image

Additional comments

Repro here

@sylveon
Copy link
Contributor

sylveon commented Jul 8, 2024

Are you sure the bug is not with the console output? Check the debugger maybe?

@HO-COOH
Copy link
Author

HO-COOH commented Jul 8, 2024

Are you sure the bug is not with the console output? Check the debugger maybe?

The break point inside the for loop is not hit. That should be clear enough.

@kennykerr
Copy link
Collaborator

For API questions I suggest: https://docs.microsoft.com/en-us/answers/topics/windows-api.html

@HO-COOH
Copy link
Author

HO-COOH commented Jul 8, 2024

@kennykerr I don't know, but both examples uses the same Windows.Foundation.WwwFormUrlDecoder class which makes me wondering. I will ask there too.

@DefaultRyan
Copy link
Member

DefaultRyan commented Jul 8, 2024

It uses the same Windows.Foundation.WwwFormUrlDecoder class, but System.Uri is not the same as Windows.Foundation.Uri. The doc page for Windows.Foundation.Uri calls out some of these potential differences in the Remarks https://learn.microsoft.com/en-us/uwp/api/windows.foundation.uri?view=winrt-26100#remarks, including potentially relevant statements about percent-encoding non-ASCII characters.

That's as far as I got, but I'm confident that this is where you're seeing behavior differences.

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

No branches or pull requests

4 participants