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

FilePicker on iOS: double quotes (0x22) in picked json file replaced by 0xAB («) the 1st time it is opened+read #22127

Closed
softlion opened this issue Apr 29, 2024 · 4 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 t/bug Something isn't working

Comments

@softlion
Copy link
Contributor

softlion commented Apr 29, 2024

Description

When using FilePicker on iOS to pick a json file, on a real device, the 1st time the file is picked its text content is not the original content. Instead every double quotes are replaced into the '«' char, and spaces after that char is replaced by a non breaking space (NBSP, 0xA0).

If picking the same file a second time, it is loaded as expected, its content is the original unchanged one: with normal double quotes and normal spaces.

On Android there is no issue, everything is working as expected the 1st time.
That code is upgraded from a Xamarin app, and is working perfectly on iOS with the Xamarin version of the app.

Steps to Reproduce

Also, I tried to use UIType.Json in the code below instead of "public.json" but UIType can't be found in net8 ? Any clue ?

            var options = new PickOptions
            {
                PickerTitle = "Select a file to import",
                FileTypes = new (
                    new Dictionary<DevicePlatform, IEnumerable<string>>
                    {
                        { DevicePlatform.Android, new [] { "application/json", "application/javascript", "application/octet-stream"} },
                        { DevicePlatform.iOS, new [] { "public.json", "public.text" } }, 
#if IOS
                        //(string) UIType.Json: used in maui, but not available otherwise ?!
#endif
                    }),
            };
                
            var fileData = await FilePicker.PickAsync(options);
            if (fileData != null)
            {
                AppSettingsFileName = fileData.FileName;
                await using var stream = await fileData.OpenReadAsync();
                using var reader = new StreamReader(stream);
                var content = reader.ReadToEnd();

                //examine content here. Only the 1st time the file is opened, it will contain those chars.
               //content[4] will be '«' (0xAB) instead of " (double quote 0x22)
               //content[5] will be NBSP (0xA0) instead of a space 0x20
               //the second time the same file is picked, the content is the regular content (ie: normal spaces and double quotes)
            }

Link to public reproduction project repository

No response

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

17.4.1

Did you find any workaround?

No.

Relevant log output

No response

@softlion softlion added the t/bug Something isn't working label Apr 29, 2024
@softlion
Copy link
Contributor Author

softlion commented Apr 29, 2024

Original file:

image

Content loaded the 1st time the picker is used. Remark the quotes transformed into another char.

image

Related source code from maui:

https://github.com/dotnet/maui/blob/main/src/Essentials/src/FileSystem/FileSystem.ios.cs

@jsuarezruiz jsuarezruiz added platform/iOS 🍎 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Apr 30, 2024
@softlion
Copy link
Contributor Author

The above content was on iPad. I tested on iPhone, and the "char transformation" is not the same!

Double quotes are replaced by those curious chars:

image

For example that char: “ is the E2 80 9C sequence.

@jaosnz-rep
Copy link
Collaborator

/similarissues

Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants