dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.15k stars 9.92k forks source link

Using trailing slash in ResourcesPath breaks resources reoslution. #56788

Open voroninp opened 1 month ago

voroninp commented 1 month ago

Is there an existing issue for this?

Describe the bug

If I use trainling slash:

builder.Services.AddLocalization(cfg => "Resources/");

IStringLocalizer cannot find resources. If I omit the slash, everything works fine.

Expected Behavior

Trainling slash should not affect the behavior.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.303

Anything else?

No response

voroninp commented 1 month ago

Here's the place in constructor of ResourceManagerStringLocalizerFactory which causes the issue:

if (!string.IsNullOrEmpty(_resourcesRelativePath))
{
    _resourcesRelativePath = _resourcesRelativePath.Replace(Path.AltDirectorySeparatorChar, '.')
        .Replace(Path.DirectorySeparatorChar, '.') + ".";
}