Skip to content

Commit c5a5f4c

Browse files
StephaneDelcroixPureWeen
authored andcommitted
[XC] trim x:Name values
fixes #27121
1 parent aa3f986 commit c5a5f4c

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/Controls/src/Build.Tasks/SetFieldVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Visit(ValueNode node, INode parentNode)
3030
{
3131
if (!IsXNameProperty(node, parentNode))
3232
return;
33-
var field = Context.Body.Method.DeclaringType.Fields.SingleOrDefault(fd => fd.Name == (string)node.Value);
33+
var field = Context.Body.Method.DeclaringType.Fields.SingleOrDefault(fd => fd.Name == ((string)node.Value).Trim());
3434
if (field == null)
3535
return;
3636
Context.IL.Emit(OpCodes.Ldarg_0);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests"
5+
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui27121">
6+
<Label x:Name=" label0" Text =" Values: 1234" TextColor="Black"/>
7+
</ContentPage>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Globalization;
5+
using System.Linq;
6+
using Microsoft.Maui.ApplicationModel;
7+
using Microsoft.Maui.Controls.Core.UnitTests;
8+
using Microsoft.Maui.Dispatching;
9+
using Microsoft.Maui.UnitTests;
10+
using Mono.Cecil;
11+
using Mono.Cecil.Cil;
12+
using NUnit.Framework;
13+
14+
namespace Microsoft.Maui.Controls.Xaml.UnitTests;
15+
16+
public partial class Maui27121
17+
{
18+
public Maui27121() => InitializeComponent();
19+
20+
public Maui27121(bool useCompiledXaml)
21+
{
22+
//this stub will be replaced at compile time
23+
}
24+
25+
[TestFixture]
26+
class Test
27+
{
28+
[SetUp]
29+
public void Setup()
30+
{
31+
Application.SetCurrentApplication(new MockApplication());
32+
DispatcherProvider.SetCurrent(new DispatcherProviderStub());
33+
}
34+
35+
[TearDown] public void TearDown() => AppInfo.SetCurrent(null);
36+
37+
[Test]
38+
public void XNameAreTrimmed([Values] bool useCompiledXaml)
39+
{
40+
var page = new Maui27121(useCompiledXaml);
41+
Assert.That(page.label0, Is.Not.Null);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)