diff --git a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs index 6d42ab748f..66b22fa9cd 100644 --- a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs +++ b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs @@ -136,10 +136,22 @@ namespace umbraco.cms.businesslogic.datatype { //CHANGE:by Allan Laustsen to fix copy nodes //if (value == null) - if (value == null || (string.IsNullOrEmpty(value.ToString()) && (this._dataType.DBType == DBTypes.Integer || this._dataType.DBType == DBTypes.Date))) - SqlHelper.ExecuteNonQuery("update cmsPropertyData set " + _dataType.DataFieldName + " = NULL where id = " + m_PropertyId); + if (value == null || + (string.IsNullOrEmpty(value.ToString()) && + (this._dataType.DBType == DBTypes.Integer || this._dataType.DBType == DBTypes.Date))) + SqlHelper.ExecuteNonQuery("update cmsPropertyData set " + _dataType.DataFieldName + + " = NULL where id = " + m_PropertyId); else - SqlHelper.ExecuteNonQuery("update cmsPropertyData set " + _dataType.DataFieldName + " = @value where id = " + m_PropertyId, SqlHelper.CreateParameter("@value", value)); + { + // we need to be sure that the value doesn't contain malformatted xml + if (_dataType.DBType == DBTypes.Ntext || _dataType.DBType == DBTypes.Nvarchar) + { + value = cms.helpers.xhtml.RemoveTroublesomeCharacters(value.ToString()); + } + SqlHelper.ExecuteNonQuery( + "update cmsPropertyData set " + _dataType.DataFieldName + " = @value where id = " + + m_PropertyId, SqlHelper.CreateParameter("@value", value)); + } } catch (Exception e) { diff --git a/src/umbraco.cms/helpers/xhtml.cs b/src/umbraco.cms/helpers/xhtml.cs index 3700b7f130..8e7d1dd3ad 100644 --- a/src/umbraco.cms/helpers/xhtml.cs +++ b/src/umbraco.cms/helpers/xhtml.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Text; using System.Text.RegularExpressions; using System.IO; @@ -146,6 +147,28 @@ namespace umbraco.cms.helpers newTag += " " + attributeSet.Groups["attributeName"].Value.ToString().ToLower() + "=\"" + attributeSet.Groups["attributeValue"].Value.ToString() + "\""; return newTag; - } + } + + public static string RemoveTroublesomeCharacters(string inString) + { + if (inString == null) return null; + + StringBuilder newString = new StringBuilder(); + char ch; + + for (int i = 0; i < inString.Length; i++) + { + + ch = inString[i]; + // remove any characters outside the valid UTF-8 range as well as all control characters + // except tabs and new lines + if ((ch < 0x00FD && ch > 0x001F) || ch == '\t' || ch == '\n' || ch == '\r') + { + newString.Append(ch); + } + } + return newString.ToString(); + + } } }