From 60f9aaae09a3c76a3054b140b15f9b9c4b6db182 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Fri, 31 May 2024 08:31:20 -0700 Subject: [PATCH 1/5] Make changes requested by Andy Black --- Src/LexText/ParserUI/HCTrace.cs | 22 ++++++++++++++++++++ Src/LexText/ParserUI/TryAWordDlg.cs | 1 + Src/LexText/ParserUI/XAmpleTrace.cs | 32 +++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/Src/LexText/ParserUI/HCTrace.cs b/Src/LexText/ParserUI/HCTrace.cs index be61fabf00..6f5cfb7417 100644 --- a/Src/LexText/ParserUI/HCTrace.cs +++ b/Src/LexText/ParserUI/HCTrace.cs @@ -4,6 +4,7 @@ using System; using System.IO; +using System.Linq; using System.Xml.Linq; using System.Xml.Xsl; using SIL.LCModel; @@ -26,6 +27,7 @@ private static ParserTraceUITransform TraceTransform public string CreateResultPage(PropertyTable propertyTable, XDocument result, bool isTrace) { + result = FixAnyDoubleQuotes(result); var args = new XsltArgumentList(); var loadErrorUri = new Uri(Path.Combine(Path.GetTempPath(), propertyTable.GetValue("cache").ProjectId.Name + "HCLoadErrors.xml")); @@ -33,5 +35,25 @@ public string CreateResultPage(PropertyTable propertyTable, XDocument result, bo args.AddParam("prmShowTrace", "", isTrace.ToString().ToLowerInvariant()); return TraceTransform.Transform(propertyTable, result, isTrace ? "HCTrace" : "HCParse", args); } + + /// + /// Convert any " sequences in the form to " so it displays correctly + /// + /// The HermitCrab XML result + /// Corrected result + private static XDocument FixAnyDoubleQuotes(XDocument result) + { + var forms = result.Descendants("Wordform"); + var form = forms.FirstOrDefault(); + if (form != null) + { + var attr = form.Attribute("form"); + if (attr != null) + { + result = XAmpleTrace.FixAnyDoubleQuotes(result, attr.Value); + } + } + return result; + } } } diff --git a/Src/LexText/ParserUI/TryAWordDlg.cs b/Src/LexText/ParserUI/TryAWordDlg.cs index 38e976a3ee..da05363989 100644 --- a/Src/LexText/ParserUI/TryAWordDlg.cs +++ b/Src/LexText/ParserUI/TryAWordDlg.cs @@ -411,6 +411,7 @@ private void m_tryItButton_Click(object sender, EventArgs e) var uri = new Uri(Path.Combine(TransformPath, "WhileTracing.htm")); m_htmlControl.URL = uri.AbsoluteUri; sWord = sWord.Replace(' ', '.'); // LT-7334 to allow for phrases; do this at the last minute + sWord = sWord.Replace("\"", """); // LT-10373 a double quote causes a crash; change it so HTML/XML works m_parserListener.Connection.TryAWordDialogIsRunning = true; // make sure this is set properly m_tryAWordResult = m_parserListener.Connection.BeginTryAWord(sWord, DoTrace, selectedTraceMorphs); // waiting for result, so disable Try It button diff --git a/Src/LexText/ParserUI/XAmpleTrace.cs b/Src/LexText/ParserUI/XAmpleTrace.cs index 3213389f35..9bf16544bf 100644 --- a/Src/LexText/ParserUI/XAmpleTrace.cs +++ b/Src/LexText/ParserUI/XAmpleTrace.cs @@ -13,6 +13,7 @@ // XAmpleTrace - Deal with results of an XAmple trace // +using System.Linq; using System.Xml.Linq; using XCore; @@ -65,8 +66,39 @@ public string CreateResultPage(PropertyTable propertyTable, XDocument result, bo { transform = ParseTransform; baseName = "XAmpleParse"; + result = FixAnyDoubleQuotes(result); } return transform.Transform(propertyTable, result, baseName); } + + /// + /// Convert any " sequences in the form to " so it displays correctly + /// + /// The XAmple XML result + /// Corrected result + private static XDocument FixAnyDoubleQuotes(XDocument result) + { + var forms = result.Descendants("form"); + var elem = forms.FirstOrDefault(); + if (elem != null) + { + result = FixAnyDoubleQuotes(result, elem.Value); + } + return result; + } + + public static XDocument FixAnyDoubleQuotes(XDocument result, string nodeValue) + { + if (nodeValue != null && nodeValue.Contains(""")) + { + // The Contains method above compared to what is replaced below appears odd + // but what is really """ is treated as """ in the node. + string fixedQuote = result.ToString().Replace(""", """); + XDocument fixedResult = XDocument.Parse(fixedQuote); + result = fixedResult; + } + + return result; + } } } From 6f2bdac0c304b25cd0aa453d53fb4bbc4ddae46b Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Fri, 31 May 2024 09:01:10 -0700 Subject: [PATCH 2/5] Generalize Andy's fix to include angle bracket and other XML characters --- Src/LexText/ParserUI/TryAWordDlg.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/LexText/ParserUI/TryAWordDlg.cs b/Src/LexText/ParserUI/TryAWordDlg.cs index da05363989..3058b1a761 100644 --- a/Src/LexText/ParserUI/TryAWordDlg.cs +++ b/Src/LexText/ParserUI/TryAWordDlg.cs @@ -411,7 +411,7 @@ private void m_tryItButton_Click(object sender, EventArgs e) var uri = new Uri(Path.Combine(TransformPath, "WhileTracing.htm")); m_htmlControl.URL = uri.AbsoluteUri; sWord = sWord.Replace(' ', '.'); // LT-7334 to allow for phrases; do this at the last minute - sWord = sWord.Replace("\"", """); // LT-10373 a double quote causes a crash; change it so HTML/XML works + sWord = new System.Xml.Linq.XText(sWord).ToString(); // LT-10373 a double quote causes a crash; change it so HTML/XML works m_parserListener.Connection.TryAWordDialogIsRunning = true; // make sure this is set properly m_tryAWordResult = m_parserListener.Connection.BeginTryAWord(sWord, DoTrace, selectedTraceMorphs); // waiting for result, so disable Try It button From ecef002cf3e9c9a7cefbfef2346baadfe18b7ef6 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Mon, 3 Jun 2024 08:27:26 -0700 Subject: [PATCH 3/5] Fix both quotes and angle brackets --- Src/LexText/ParserUI/TryAWordDlg.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Src/LexText/ParserUI/TryAWordDlg.cs b/Src/LexText/ParserUI/TryAWordDlg.cs index 3058b1a761..f158059a0c 100644 --- a/Src/LexText/ParserUI/TryAWordDlg.cs +++ b/Src/LexText/ParserUI/TryAWordDlg.cs @@ -410,8 +410,9 @@ private void m_tryItButton_Click(object sender, EventArgs e) // Display a "processing" message (and include info on how to improve the results) var uri = new Uri(Path.Combine(TransformPath, "WhileTracing.htm")); m_htmlControl.URL = uri.AbsoluteUri; + sWord = new System.Xml.Linq.XText(sWord).ToString(); // LT-10373 XML special characters cause a crash; change it so HTML/XML works + sWord = sWord.Replace("\"", """); // LT-10373 same for double quote sWord = sWord.Replace(' ', '.'); // LT-7334 to allow for phrases; do this at the last minute - sWord = new System.Xml.Linq.XText(sWord).ToString(); // LT-10373 a double quote causes a crash; change it so HTML/XML works m_parserListener.Connection.TryAWordDialogIsRunning = true; // make sure this is set properly m_tryAWordResult = m_parserListener.Connection.BeginTryAWord(sWord, DoTrace, selectedTraceMorphs); // waiting for result, so disable Try It button From 9dcdde4c2bf231a6f607d52e7ebfe2565fcaa616 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Wed, 5 Jun 2024 08:15:10 -0700 Subject: [PATCH 4/5] Remove FixAnyDoubleQuote (it wasn't being used) --- Src/LexText/ParserUI/HCTrace.cs | 21 ------------------- Src/LexText/ParserUI/XAmpleTrace.cs | 31 ----------------------------- 2 files changed, 52 deletions(-) diff --git a/Src/LexText/ParserUI/HCTrace.cs b/Src/LexText/ParserUI/HCTrace.cs index 6f5cfb7417..2d67760436 100644 --- a/Src/LexText/ParserUI/HCTrace.cs +++ b/Src/LexText/ParserUI/HCTrace.cs @@ -27,7 +27,6 @@ private static ParserTraceUITransform TraceTransform public string CreateResultPage(PropertyTable propertyTable, XDocument result, bool isTrace) { - result = FixAnyDoubleQuotes(result); var args = new XsltArgumentList(); var loadErrorUri = new Uri(Path.Combine(Path.GetTempPath(), propertyTable.GetValue("cache").ProjectId.Name + "HCLoadErrors.xml")); @@ -35,25 +34,5 @@ public string CreateResultPage(PropertyTable propertyTable, XDocument result, bo args.AddParam("prmShowTrace", "", isTrace.ToString().ToLowerInvariant()); return TraceTransform.Transform(propertyTable, result, isTrace ? "HCTrace" : "HCParse", args); } - - /// - /// Convert any " sequences in the form to " so it displays correctly - /// - /// The HermitCrab XML result - /// Corrected result - private static XDocument FixAnyDoubleQuotes(XDocument result) - { - var forms = result.Descendants("Wordform"); - var form = forms.FirstOrDefault(); - if (form != null) - { - var attr = form.Attribute("form"); - if (attr != null) - { - result = XAmpleTrace.FixAnyDoubleQuotes(result, attr.Value); - } - } - return result; - } } } diff --git a/Src/LexText/ParserUI/XAmpleTrace.cs b/Src/LexText/ParserUI/XAmpleTrace.cs index 9bf16544bf..9c5475d41a 100644 --- a/Src/LexText/ParserUI/XAmpleTrace.cs +++ b/Src/LexText/ParserUI/XAmpleTrace.cs @@ -66,39 +66,8 @@ public string CreateResultPage(PropertyTable propertyTable, XDocument result, bo { transform = ParseTransform; baseName = "XAmpleParse"; - result = FixAnyDoubleQuotes(result); } return transform.Transform(propertyTable, result, baseName); } - - /// - /// Convert any " sequences in the form to " so it displays correctly - /// - /// The XAmple XML result - /// Corrected result - private static XDocument FixAnyDoubleQuotes(XDocument result) - { - var forms = result.Descendants("form"); - var elem = forms.FirstOrDefault(); - if (elem != null) - { - result = FixAnyDoubleQuotes(result, elem.Value); - } - return result; - } - - public static XDocument FixAnyDoubleQuotes(XDocument result, string nodeValue) - { - if (nodeValue != null && nodeValue.Contains(""")) - { - // The Contains method above compared to what is replaced below appears odd - // but what is really """ is treated as """ in the node. - string fixedQuote = result.ToString().Replace(""", """); - XDocument fixedResult = XDocument.Parse(fixedQuote); - result = fixedResult; - } - - return result; - } } } From c418b9786f05fc7f569e3c0aa55fa903b3c49e10 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Wed, 5 Jun 2024 08:22:01 -0700 Subject: [PATCH 5/5] Remove unneeded System.Ling --- Src/LexText/ParserUI/HCTrace.cs | 1 - Src/LexText/ParserUI/XAmpleTrace.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Src/LexText/ParserUI/HCTrace.cs b/Src/LexText/ParserUI/HCTrace.cs index 2d67760436..be61fabf00 100644 --- a/Src/LexText/ParserUI/HCTrace.cs +++ b/Src/LexText/ParserUI/HCTrace.cs @@ -4,7 +4,6 @@ using System; using System.IO; -using System.Linq; using System.Xml.Linq; using System.Xml.Xsl; using SIL.LCModel; diff --git a/Src/LexText/ParserUI/XAmpleTrace.cs b/Src/LexText/ParserUI/XAmpleTrace.cs index 9c5475d41a..3213389f35 100644 --- a/Src/LexText/ParserUI/XAmpleTrace.cs +++ b/Src/LexText/ParserUI/XAmpleTrace.cs @@ -13,7 +13,6 @@ // XAmpleTrace - Deal with results of an XAmple trace // -using System.Linq; using System.Xml.Linq; using XCore;