Skip to content

Commit 30f21ac

Browse files
committed
fix!: Fix resource dictionary path handling
BREAKING CHANGE: Source paths starting with '/' are now considered relative to project root instead of current file.
1 parent ee16529 commit 30f21ac

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Uno.UI.Tests/Windows_UI_Xaml/Given_ResourceDictionary.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,16 @@ public void When_Relative_Path_With_Leading_Slash_From_Root()
712712
Assert.AreEqual(withoutSlash, withSlash);
713713
}
714714

715+
[TestMethod]
716+
public void When_Relative_Path_With_Leading_Slash_From_Non_Root()
717+
{
718+
var withSlash = XamlFilePathHelper.ResolveAbsoluteSource("Dictionaries/App.xaml", "/App/Xaml/Test_Dictionary.xaml");
719+
var withoutSlash = XamlFilePathHelper.ResolveAbsoluteSource("Dictionaries/App.xaml", "App/Xaml/Test_Dictionary.xaml");
720+
721+
Assert.AreEqual("App/Xaml/Test_Dictionary.xaml", withSlash);
722+
Assert.AreEqual("Dictionaries/App/Xaml/Test_Dictionary.xaml", withoutSlash);
723+
}
724+
715725
[TestMethod]
716726
public void When_SharedHelpers_FindResource()
717727
{

src/Uno.UI/UI/Xaml/XamlFilePathHelper.shared.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ internal static string ResolveAbsoluteSource(string origin, string relativeTarge
2727
var trimmedPath = relativeTargetPath.TrimStart(AppXIdentifier);
2828
return trimmedPath;
2929
}
30-
31-
// Strip leading forward-slash, if any, to match the path the target file is indexed by
32-
relativeTargetPath = relativeTargetPath.TrimStart(new[] { '/' });
30+
else if (relativeTargetPath.StartsWith("/", StringComparison.Ordinal))
31+
{
32+
return relativeTargetPath.Substring(1);
33+
}
3334

3435
var originDirectory = Path.GetDirectoryName(origin);
3536
if (originDirectory.IsNullOrWhiteSpace())

0 commit comments

Comments
 (0)