dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

`LoadFile` in `src/Core/src/Platform/iOS/MauiWKWebView.cs` ignore directories. #23315

Open kxc-wraikny opened 3 months ago

kxc-wraikny commented 3 months ago

Description

In macOS (net8.0-maccatalyst), I wrote the following code in order to open Resources/Raw/foo/bar.html in WebView.

WebView.Source = new UrlWebViewSource {
    Url="foo/bar.html",.
};

The directory name foo/ is ignored and bar.html is tried to be read.

I checked the implementation and found that the directory name is ignored in the following places.

https://github.com/dotnet/maui/blob/45a86865ffc44a501b1c4c8d6b50ee419d1696b9/src/Core/src/Platform/iOS/MauiWKWebView.cs#L176-L183

LoadFile is called from LoadUrlAsync because foo/bar.html is a invalid format URI.

https://github.com/dotnet/maui/blob/45a86865ffc44a501b1c4c8d6b50ee419d1696b9/src/Core/src/Platform/iOS/MauiWKWebView.cs#L120-L134

It was possible to open the file from Resources/Raw/index.html with a reference to <a href="foo/bar.html" >foo/bar</a>". It was also possible to open the file by getting the full path from OpenAppPackageFileAsync as described in the workaround.

Sorry if this is a limiting issue for other platforms such as iOS, however in that case it would be kind if it is commented in the documentation or source code.

Thanks.

Steps to Reproduce

  1. Create a file Resources/Raw/foo/bar.html.
  2. Create a Page with <WebView Source="foo/bar.html" /> element.

Link to public reproduction project repository

https://github.com/kxc-wraikny/webview_ignores_subdir_on_macos_reproduction

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

macOS Sonoma 14.5

Did you find any workaround?

    private async Task InitializeWebView()
    {
        using var stream = await FileSystem.OpenAppPackageFileAsync("foo/bar.html");
        if (stream is FileStream f)
        {
            WebView.Source = new UrlWebViewSource {
                Url=f.Name,
            };
        }
    }

Relevant log output

No response

github-actions[bot] commented 3 months ago

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!

Open similar issues:

Closed similar issues:

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

kxc-wraikny commented 3 months ago

Hi @kxc-wraikny. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

I have added link to the reproduction repo.

ninachen03 commented 3 months ago

I can repro this issue on the latest Visual Studio 17.6.12(build410) (8.0.61 & 8.0.21)