Skip to content

Commit

Permalink
fix!: Fix resource dictionary path handling
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Source paths starting with '/' are now considered relative to project root instead of current file.
  • Loading branch information
Youssef1313 committed Sep 28, 2021
1 parent ee16529 commit 30f21ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/Uno.UI.Tests/Windows_UI_Xaml/Given_ResourceDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,16 @@ public void When_Relative_Path_With_Leading_Slash_From_Root()
Assert.AreEqual(withoutSlash, withSlash);
}

[TestMethod]
public void When_Relative_Path_With_Leading_Slash_From_Non_Root()
{
var withSlash = XamlFilePathHelper.ResolveAbsoluteSource("Dictionaries/App.xaml", "/App/Xaml/Test_Dictionary.xaml");
var withoutSlash = XamlFilePathHelper.ResolveAbsoluteSource("Dictionaries/App.xaml", "App/Xaml/Test_Dictionary.xaml");

Assert.AreEqual("App/Xaml/Test_Dictionary.xaml", withSlash);
Assert.AreEqual("Dictionaries/App/Xaml/Test_Dictionary.xaml", withoutSlash);
}

[TestMethod]
public void When_SharedHelpers_FindResource()
{
Expand Down
7 changes: 4 additions & 3 deletions src/Uno.UI/UI/Xaml/XamlFilePathHelper.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ internal static string ResolveAbsoluteSource(string origin, string relativeTarge
var trimmedPath = relativeTargetPath.TrimStart(AppXIdentifier);
return trimmedPath;
}

// Strip leading forward-slash, if any, to match the path the target file is indexed by
relativeTargetPath = relativeTargetPath.TrimStart(new[] { '/' });
else if (relativeTargetPath.StartsWith("/", StringComparison.Ordinal))
{
return relativeTargetPath.Substring(1);
}

var originDirectory = Path.GetDirectoryName(origin);
if (originDirectory.IsNullOrWhiteSpace())
Expand Down

0 comments on commit 30f21ac

Please sign in to comment.