Skip to content

Commit

Permalink
Added function GetEscapedXPathStringForAttributeValue() to prevent cr…
Browse files Browse the repository at this point in the history
…ash due to invalid xpath query strings.
  • Loading branch information
NileshGhodekar committed Sep 21, 2018
1 parent 4cb8469 commit 79c8d6c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
9 changes: 8 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

All notable changes to MIMConfigDocumenter project will be documented in this file. The "Unreleased" section at the top is for keeping track of important changes that might make it to upcoming releases.

------------
### Version 1.18.0921.0

#### Fixed

* Service Config report generation may crash if the config value resulted in invalid XPath query string.

------------

### Version 1.18.0824.0

#### Fixed

* Performance improvements. The configuration report should get generated much more quickly now.
* Fixed an issue where a configuration setting did not rendor correctly if it had html markup characters.
* Fixed an issue where a configuration setting did not render correctly if it had html mark-up characters.

------------

Expand Down
36 changes: 36 additions & 0 deletions src/MIMConfigDocumenter/Documenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace MIMConfigDocumenter
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web.UI;
using System.Xml;
using System.Xml.Linq;
Expand Down Expand Up @@ -439,6 +440,41 @@ public static string GetAttributeType(string syntax)
}
}

/// <summary>
/// Gets the escaped XPath string for querying an attribute value.
/// </summary>
/// <param name="input">The input string</param>
/// <returns>An equivalent XPath string with single and double quotes characters are properly escaped.</returns>
public static string GetEscapedXPathStringForAttributeValue(string input)
{
if (input == null)
{
return input;
}

// If input has no ' then enclose it in a '
if (!input.Contains(HtmlTextWriter.SingleQuoteChar))
{
return string.Format("{0}{1}{0}", HtmlTextWriter.SingleQuoteChar, input);
}

// If input has no " then enclose it in a "
if (!input.Contains(HtmlTextWriter.DoubleQuoteChar))
{
return string.Format("{0}{1}{0}", HtmlTextWriter.DoubleQuoteChar, input);
}

// If input has both " and ' in it then use concat function
var parts = input.Split(new char[] { HtmlTextWriter.DoubleQuoteChar }, StringSplitOptions.None);
var sb = new StringBuilder("concat(");
foreach (var part in parts)
{
sb.AppendFormat("{0}{1}{0},'{0}',", HtmlTextWriter.DoubleQuoteChar, part);
}

return sb.ToString().TrimEnd(',') + ")";
}

/// <summary>
/// Gets the metaverse configuration report.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/MIMConfigDocumenter/ServiceCommonDocumenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ protected bool TestAttributeValueChange(string attributeName, string attributeVa
protected bool TestAttributeValueChange(string attributeName, string attributeValue, DataRowState attributeOperation, string locale)
{
var operation = attributeOperation == DataRowState.Modified ? "Replace" : attributeOperation == DataRowState.Added ? "Add" : attributeOperation == DataRowState.Deleted ? "Delete" : "Unknown";
return this.CurrentChangeObject.XPathSelectElement("Changes/ImportChange[AttributeName = '" + attributeName + "' and AttributeValue = '" + attributeValue + "' and Operation = '" + operation + (locale != ServiceCommonDocumenter.InvariantLocale ? "' and Locale = '" + locale : string.Empty + "']")) != null;
return this.CurrentChangeObject.XPathSelectElement("Changes/ImportChange[AttributeName = '" + attributeName + "' and AttributeValue = " + Documenter.GetEscapedXPathStringForAttributeValue(attributeValue) + " and Operation = '" + operation + (locale != ServiceCommonDocumenter.InvariantLocale ? "' and Locale = '" + locale : string.Empty + "']")) != null;
}

/// <summary>
Expand Down Expand Up @@ -714,6 +714,13 @@ protected AttributeChange GetAttributeChange(string attributeName)

return attributeChange;
}
catch (XPathException e)
{
var errorMsg = e.Message + "Attribute Name : '" + attributeName + "'. " + e.StackTrace;
Logger.Instance.WriteError(errorMsg);

return new AttributeChange(attributeName);
}
finally
{
Logger.Instance.WriteMethodExit("Attribute Name : '{0}'", attributeName);
Expand Down
4 changes: 2 additions & 2 deletions src/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class VersionInfo
/// Build Number (MMDD)
/// Revision (if any on the same day)
/// </summary>
internal const string Version = "1.18.0824.0";
internal const string Version = "1.18.0921.0";

/// <summary>
/// File Version information for the assembly consists of the following four values:
Expand All @@ -31,6 +31,6 @@ internal static class VersionInfo
/// Build Number (MMDD)
/// Revision (if any on the same day)
/// </summary>
internal const string FileVersion = "1.18.0824.0";
internal const string FileVersion = "1.18.0921.0";
}
}

0 comments on commit 79c8d6c

Please sign in to comment.