Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure x:Uid is set only when both name and namespace are correct #19148

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3328,7 +3328,8 @@ private void BuildExtendedProperties(IIndentedStringBuilder outerwriter, XamlObj
{
writer.AppendLineInvariantIndented("// Load {0}", member.Value);
}
else if (member.Member.Name == "Uid")
else if (member.Member.Name == "Uid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might need to be fixed as well:

var localizedObject = FindMember(objectDefinition, "Uid");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be var localizedObject = FindMember(objectDefinition, "Uid", XamlConstants.XamlXmlNamespace)

A test that covers the code path I mentioned may be needed as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Youssef1313 ! Thanks for the feedback. I'm so sorry for not being able to do this earlier.

A test that covers the code path I mentioned may be needed as well.

Do you mean to add a test for the GenerateFile method? Not sure how to add one for this. Can you give some tips please?

&& member.Member.PreferredXamlNamespace == XamlConstants.XamlXmlNamespace)
{
uidMember = member;
writer.AppendLineIndented($"{GlobalPrefix}Uno.UI.Helpers.MarkupHelper.SetXUid({closureName}, \"{objectUid}\");");
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.UI.RuntimeTests/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@
<data name="When_xUid_Root.Title" xml:space="preserve">
<value>en-US Value for When_xUid_Root.Title</value>
</data>
<data name="When_xUid_Conflicts_With_AttachedProperty_Named_Uid.Text" xml:space="preserve">
<value>en-US Value for When_xUid_Conflicts_With_AttachedProperty_Named_Uid</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<UserControl
x:Class="Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls.When_xUid_Conflicts_With_AttachedProperty_Named_Uid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">

<StackPanel>
<TextBlock x:Name="xUidTextBlock"
x:Uid="When_xUid_Conflicts_With_AttachedProperty_Named_Uid"
x:FieldModifier="public" />
<TextBlock x:Name="attachedPropertyUidTextBlock"
local:Uids.Uid="AttachedPropertyUid"
x:FieldModifier="public" />
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls
{
public static class Uids
{
public static readonly DependencyProperty UidProperty = DependencyProperty.RegisterAttached(
"Uid",
typeof(string),
typeof(Uids),
new PropertyMetadata(default));

public static string GetUid(DependencyObject dependencyObject)
{
return (string)dependencyObject.GetValue(UidProperty);
}

public static void SetUid(DependencyObject dependencyObject, string uid)
{
dependencyObject.SetValue(UidProperty, uid);
}
}

public sealed partial class When_xUid_Conflicts_With_AttachedProperty_Named_Uid : UserControl
{
public When_xUid_Conflicts_With_AttachedProperty_Named_Uid()
{
this.InitializeComponent();
Loaded += When_xUid_Has_Name_Conflict_Loaded;
}

private void When_xUid_Has_Name_Conflict_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
9 changes: 9 additions & 0 deletions src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_xUid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,14 @@ public void When_xUid_On_Root()
var SUT = new When_xUid_On_Root();
Assert.AreEqual("en-US Value for When_xUid_Root.Title", SUT.Title);
}

[TestMethod]
public void When_xUid_Conflicts_With_AttachedProperty_Named_Uid()
{
var SUT = new When_xUid_Conflicts_With_AttachedProperty_Named_Uid();
Assert.AreEqual("en-US Value for When_xUid_Conflicts_With_AttachedProperty_Named_Uid", SUT.xUidTextBlock.Text);
var attachedPropertyUidValue = Uids.GetUid(SUT.attachedPropertyUidTextBlock);
Assert.AreEqual("AttachedPropertyUid", attachedPropertyUidValue);
}
}
#endif
Loading