Browse Source
feat(XamlX): Trim text before invoke Color.Parse (#16649)
* test: Add falling test case
* feat(XamlX): trim text before invoke Color.Parse
pull/16616/head
workgroupengineering
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
19 additions and
0 deletions
-
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs
-
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/AvaloniaIntrinsicsTests.cs
|
|
|
@ -172,6 +172,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
@ -108,6 +108,24 @@ public class AvaloniaIntrinsicsTests : XamlTestBase |
|
|
|
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 |
|
|
|
|