diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2017-01-26 09:25:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-26 09:25:22 +0100 |
commit | e3f193712b0c9d489bef2fe7cbcfe6581135939f (patch) | |
tree | 6197895d80297756b82132e388d2fd8ea3270d5d | |
parent | ccf784656de12d5b4c54bd09e64da2333f3351d0 (diff) | |
download | xamarin-forms-e3f193712b0c9d489bef2fe7cbcfe6581135939f.tar.gz xamarin-forms-e3f193712b0c9d489bef2fe7cbcfe6581135939f.tar.bz2 xamarin-forms-e3f193712b0c9d489bef2fe7cbcfe6581135939f.zip |
[Xaml] support CDATA (#698)
4 files changed, 66 insertions, 1 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml new file mode 100644 index 00000000..cb280fcb --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Xamarin.Forms.Xaml.UnitTests.Bz40906"> + <Label x:Name="label0"> + <![CDATA[Foo]]> + </Label> + <Label x:Name="label1"> + <![CDATA[Foo]]>Bar<![CDATA[>><<]]> + </Label> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml.cs new file mode 100644 index 00000000..dd734550 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz40906 : ContentPage + { + public Bz40906() + { + InitializeComponent(); + } + + public Bz40906(bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [SetUp] + public void Setup() + { + Device.PlatformServices = new MockPlatformServices(); + } + + [TearDown] + public void TearDown() + { + Device.PlatformServices = null; + } + + [TestCase(true)] + [TestCase(false)] + public void ParsingCDATA(bool useCompiledXaml) + { + var page = new Bz40906(useCompiledXaml); + Assert.AreEqual("Foo", page.label0.Text); + Assert.AreEqual("FooBar>><<", page.label1.Text); +} + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj index a3df2b7d..8fb0cb4c 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -406,6 +406,9 @@ <Compile Include="Issues\Unreported008.xaml.cs"> <DependentUpon>Unreported008.xaml</DependentUpon> </Compile> + <Compile Include="Issues\Bz40906.xaml.cs"> + <DependentUpon>Bz40906.xaml</DependentUpon> + </Compile> <Compile Include="Issues\Bz45179.xaml.cs"> <DependentUpon>Bz45179.xaml</DependentUpon> </Compile> @@ -742,6 +745,9 @@ <EmbeddedResource Include="Issues\Unreported008.xaml"> <Generator>MSBuild:UpdateDesignTimeXaml</Generator> </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz40906.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> <EmbeddedResource Include="Issues\Bz45179.xaml"> <Generator>MSBuild:UpdateDesignTimeXaml</Generator> </EmbeddedResource> diff --git a/Xamarin.Forms.Xaml/XamlParser.cs b/Xamarin.Forms.Xaml/XamlParser.cs index e5c49804..456aad6a 100644 --- a/Xamarin.Forms.Xaml/XamlParser.cs +++ b/Xamarin.Forms.Xaml/XamlParser.cs @@ -104,7 +104,11 @@ namespace Xamarin.Forms.Xaml case XmlNodeType.Whitespace: break; case XmlNodeType.Text: - node.CollectionItems.Add(new ValueNode(reader.Value.Trim(), (IXmlNamespaceResolver)reader)); + case XmlNodeType.CDATA: + if (node.CollectionItems.Count == 1 && node.CollectionItems[0] is ValueNode) + ((ValueNode)node.CollectionItems[0]).Value += reader.Value.Trim(); + else + node.CollectionItems.Add(new ValueNode(reader.Value.Trim(), (IXmlNamespaceResolver)reader)); break; default: Debug.WriteLine("Unhandled node {0} {1} {2}", reader.NodeType, reader.Name, reader.Value); |