[Xaml] support CDATA (#698)
authorStephane Delcroix <stephane@delcroix.org>
Thu, 26 Jan 2017 08:25:22 +0000 (09:25 +0100)
committerKangho Hur <kangho.hur@samsung.com>
Fri, 24 Mar 2017 04:15:52 +0000 (13:15 +0900)
Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml [new file with mode: 0644]
Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml.cs [new file with mode: 0644]
Xamarin.Forms.Xaml/XamlParser.cs

diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz40906.xaml
new file mode 100644 (file)
index 0000000..cb280fc
--- /dev/null
@@ -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 (file)
index 0000000..dd73455
--- /dev/null
@@ -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);
+}
+               }
+       }
+}
index e5c4980..456aad6 100644 (file)
@@ -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);