Added umbraco.Settings entry for controlling what document element types are parsed as DynamicXml

Added documentElement checking to DynamicXml convert for DynamicNode property get to solve a potential issue with XHTML RTEs
Fixed issue with calling @Model.Children.First() in testing (null Children in testing)
Put some commented placeholder code in .XPath->DynamicNodeList inside DynamicNode.cs for future return of DynamicXml if not valid List<NodeFactory.Node>
This commit is contained in:
agrath@gmail.com
2011-02-20 19:55:06 -13:00
parent 6b431eb000
commit 03441fab21
3 changed files with 75 additions and 3 deletions

View File

@@ -103,6 +103,16 @@
<templates>
<useAspNetMasterPages>true</useAspNetMasterPages>
</templates>
<scripting>
<razor>
<!-- razor DynamicNode typecasting detects XML and returns DynamicXml - Root elements that won't convert to DynamicXml -->
<notDynamicXmlDocumentElements>
<element>p</element>
<element>div</element>
</notDynamicXmlDocumentElements>
</razor>
</scripting>
<!-- This moves the asp.net viewstate data to the end of the html document instead of having it in the beginning-->
<viewstateMoverModule enable="false" />

View File

@@ -62,6 +62,12 @@ namespace umbraco.MacroEngines
{
get
{
List<INode> children = n.ChildrenAsList;
//testing
if (children.Count == 0 && n.Id == 0)
{
return new DynamicNodeList(new List<INode> { this.n });
}
return new DynamicNodeList(n.ChildrenAsList);
}
}
@@ -102,6 +108,16 @@ namespace umbraco.MacroEngines
}
catch (Exception) { } //swallow the exceptions - the returned nodes might not be full nodes, e.g. property
}
//Wanted to do this, but because we return DynamicNodeList here, the only
//common parent class is DynamicObject
//maybe some future refactoring will solve this?
//if (nodeFactoryNodeList.Count == 0)
//{
// //if the xpath resulted in a node set, but none of them could be converted to NodeFactory.Node
// XElement xElement = XElement.Parse(node.OuterXml);
// //return
// return new DynamicXml(xElement);
//}
//convert the NodeFactory nodelist to IEnumerable<DynamicNode> and return it as a DynamicNodeList
return new DynamicNodeList(nodeFactoryNodeList.ConvertAll(nfNode => new DynamicNode(nfNode)));
}
@@ -245,12 +261,33 @@ namespace umbraco.MacroEngines
//a really rough check to see if this may be valid xml
if (sResult.StartsWith("<") && sResult.EndsWith(">") && sResult.Contains("/"))
{
XElement e = XElement.Parse(sResult, LoadOptions.None);
if (e != null)
try
{
result = new DynamicXml(e);
XElement e = XElement.Parse(sResult, LoadOptions.None);
if (e != null)
{
//check that the document element is not one of the disallowed elements
//allows RTE to still return as html if it's valid xhtml
string documentElement = e.Name.LocalName;
if (!UmbracoSettings.NotDynamicXmlDocumentElements.Any(tag =>
string.Equals(tag, documentElement, StringComparison.CurrentCultureIgnoreCase)))
{
result = new DynamicXml(e);
return true;
}
else
{
//we will just return this as a string
return true;
}
}
}
catch (Exception)
{
//we will just return this as a string
return true;
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Web;
using System.Web.Caching;
using System.Xml;
using umbraco.BusinessLogic;
using System.Collections.Generic;
namespace umbraco
{
@@ -353,6 +354,30 @@ namespace umbraco
}
}
/// <summary>
/// razor DynamicNode typecasting detects XML and returns DynamicXml - Root elements that won't convert to DynamicXml
/// </summary>
public static List<string> NotDynamicXmlDocumentElements
{
get
{
try
{
List<string> items = new List<string>();
XmlNode root = GetKeyAsNode("/settings/scripting/razor/notDynamicXmlDocumentElements");
foreach (XmlNode element in root.SelectNodes(".//element"))
{
items.Add(element.InnerText);
}
return items;
}
catch
{
return new List<string>() { "p", "div" };
}
}
}
/// <summary>
/// Gets a value indicating whether umbraco will clone XML cache on publish.
/// </summary>