Skip to content

Commit 79c8d6c

Browse files
Added function GetEscapedXPathStringForAttributeValue() to prevent crash due to invalid xpath query strings.
1 parent 4cb8469 commit 79c8d6c

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

ChangeLog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
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.
44

5+
------------
6+
### Version 1.18.0921.0
7+
8+
#### Fixed
9+
10+
* Service Config report generation may crash if the config value resulted in invalid XPath query string.
11+
512
------------
613

714
### Version 1.18.0824.0
815

916
#### Fixed
1017

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

1421
------------
1522

src/MIMConfigDocumenter/Documenter.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace MIMConfigDocumenter
2020
using System.IO;
2121
using System.Linq;
2222
using System.Reflection;
23+
using System.Text;
2324
using System.Web.UI;
2425
using System.Xml;
2526
using System.Xml.Linq;
@@ -439,6 +440,41 @@ public static string GetAttributeType(string syntax)
439440
}
440441
}
441442

443+
/// <summary>
444+
/// Gets the escaped XPath string for querying an attribute value.
445+
/// </summary>
446+
/// <param name="input">The input string</param>
447+
/// <returns>An equivalent XPath string with single and double quotes characters are properly escaped.</returns>
448+
public static string GetEscapedXPathStringForAttributeValue(string input)
449+
{
450+
if (input == null)
451+
{
452+
return input;
453+
}
454+
455+
// If input has no ' then enclose it in a '
456+
if (!input.Contains(HtmlTextWriter.SingleQuoteChar))
457+
{
458+
return string.Format("{0}{1}{0}", HtmlTextWriter.SingleQuoteChar, input);
459+
}
460+
461+
// If input has no " then enclose it in a "
462+
if (!input.Contains(HtmlTextWriter.DoubleQuoteChar))
463+
{
464+
return string.Format("{0}{1}{0}", HtmlTextWriter.DoubleQuoteChar, input);
465+
}
466+
467+
// If input has both " and ' in it then use concat function
468+
var parts = input.Split(new char[] { HtmlTextWriter.DoubleQuoteChar }, StringSplitOptions.None);
469+
var sb = new StringBuilder("concat(");
470+
foreach (var part in parts)
471+
{
472+
sb.AppendFormat("{0}{1}{0},'{0}',", HtmlTextWriter.DoubleQuoteChar, part);
473+
}
474+
475+
return sb.ToString().TrimEnd(',') + ")";
476+
}
477+
442478
/// <summary>
443479
/// Gets the metaverse configuration report.
444480
/// </summary>

src/MIMConfigDocumenter/ServiceCommonDocumenter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ protected bool TestAttributeValueChange(string attributeName, string attributeVa
525525
protected bool TestAttributeValueChange(string attributeName, string attributeValue, DataRowState attributeOperation, string locale)
526526
{
527527
var operation = attributeOperation == DataRowState.Modified ? "Replace" : attributeOperation == DataRowState.Added ? "Add" : attributeOperation == DataRowState.Deleted ? "Delete" : "Unknown";
528-
return this.CurrentChangeObject.XPathSelectElement("Changes/ImportChange[AttributeName = '" + attributeName + "' and AttributeValue = '" + attributeValue + "' and Operation = '" + operation + (locale != ServiceCommonDocumenter.InvariantLocale ? "' and Locale = '" + locale : string.Empty + "']")) != null;
528+
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;
529529
}
530530

531531
/// <summary>
@@ -714,6 +714,13 @@ protected AttributeChange GetAttributeChange(string attributeName)
714714

715715
return attributeChange;
716716
}
717+
catch (XPathException e)
718+
{
719+
var errorMsg = e.Message + "Attribute Name : '" + attributeName + "'. " + e.StackTrace;
720+
Logger.Instance.WriteError(errorMsg);
721+
722+
return new AttributeChange(attributeName);
723+
}
717724
finally
718725
{
719726
Logger.Instance.WriteMethodExit("Attribute Name : '{0}'", attributeName);

src/VersionInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal static class VersionInfo
2222
/// Build Number (MMDD)
2323
/// Revision (if any on the same day)
2424
/// </summary>
25-
internal const string Version = "1.18.0824.0";
25+
internal const string Version = "1.18.0921.0";
2626

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

0 commit comments

Comments
 (0)