Skip to content

Commit

Permalink
feat(XamlX): Trim text before invoke Color.Parse (#16649)
Browse files Browse the repository at this point in the history
* test: Add falling test case

* feat(XamlX): trim text before invoke Color.Parse
  • Loading branch information
workgroupengineering authored Aug 12, 2024
1 parent dcae756 commit ec655a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ bool ReturnOnParseError(string title, out IXamlAstValueNode? result)

if (type.Equals(types.Color))
{
text = text.Trim();
if (!Color.TryParse(text, out Color color))
{
return ReturnOnParseError($"Unable to parse \"{text}\" as a color", out result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ void AssertDiagnostic(RuntimeXamlDiagnostic runtimeXamlDiagnostic, string contai
Assert.Contains(contains, runtimeXamlDiagnostic.Title, StringComparison.OrdinalIgnoreCase);
}
}

/// <summary>
/// GitHub Issue <see href="https://github.com/AvaloniaUI/Avalonia/issues/15320">#15320</see>
/// </summary>
[Fact]
public void Should_Parse_Formatted_Color_Tag()
{
var target = AvaloniaRuntimeXamlLoader
.Parse<ResourceDictionary>($"""
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="ColorKey">
White
</Color>
</ResourceDictionary>
""");
Assert.NotNull(target);
}
}

public class TestIntrinsicsControl : Control
Expand Down

0 comments on commit ec655a9

Please sign in to comment.