Revision: 6500
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=6500&view=rev
Author:   dnaber
Date:     2012-02-11 01:57:45 +0000 (Sat, 11 Feb 2012)
Log Message:
-----------
bugfix: the "contextoffset" position in the XML output was wrong when there 
were XML-escaped characters in the context

Modified Paths:
--------------
    trunk/JLanguageTool/CHANGES.txt
    trunk/JLanguageTool/src/java/org/languagetool/tools/StringTools.java
    trunk/JLanguageTool/src/test/org/languagetool/tools/StringToolsTest.java

Modified: trunk/JLanguageTool/CHANGES.txt
===================================================================
--- trunk/JLanguageTool/CHANGES.txt     2012-02-11 01:33:11 UTC (rev 6499)
+++ trunk/JLanguageTool/CHANGES.txt     2012-02-11 01:57:45 UTC (rev 6500)
@@ -20,6 +20,8 @@
    -added a few new rules
 
  -bugfix: the "fromx" position in the XML output was wrong sometimes
+ -bugfix: the "contextoffset" position in the XML output was wrong
+  when there were XML-escaped characters in the context
 
  -GUI: errors are now marked with red background instead of red font
   so whitespace problems can easily be spotted

Modified: trunk/JLanguageTool/src/java/org/languagetool/tools/StringTools.java
===================================================================
--- trunk/JLanguageTool/src/java/org/languagetool/tools/StringTools.java        
2012-02-11 01:33:11 UTC (rev 6499)
+++ trunk/JLanguageTool/src/java/org/languagetool/tools/StringTools.java        
2012-02-11 01:57:45 UTC (rev 6500)
@@ -338,7 +338,7 @@
       xml.append(" msg=\"" + escapeXMLForAPIOutput(msg) + "\"");
       final String START_MARKER = "__languagetool_start_marker";
       String context = Tools.getContext(match.getFromPos(), match.getToPos(),
-          text, contextSize, START_MARKER, "", true);
+          text, contextSize, START_MARKER, "", false);
       xml.append(" replacements=\""
           + escapeXMLForAPIOutput(listToString(
               match.getSuggestedReplacements(), "#")) + "\"");
@@ -346,10 +346,9 @@
       final int contextOffset = context.indexOf(START_MARKER);
       context = context.replaceFirst(START_MARKER, "");
       context = context.replaceAll("[\n\r]", " ");
-      xml.append(" context=\"" + context + "\"");
+      xml.append(" context=\"" + StringTools.escapeXML(context) + "\"");
       xml.append(" contextoffset=\"" + contextOffset + "\"");
-      xml.append(" errorlength=\"" + (match.getToPos() - match.getFromPos())
-          + "\"");
+      xml.append(" errorlength=\"" + (match.getToPos() - match.getFromPos()) + 
"\"");
       xml.append("/>\n");
     }
     if (xmlMode == XmlPrintMode.END_XML || xmlMode == XmlPrintMode.NORMAL_XML) 
{

Modified: 
trunk/JLanguageTool/src/test/org/languagetool/tools/StringToolsTest.java
===================================================================
--- trunk/JLanguageTool/src/test/org/languagetool/tools/StringToolsTest.java    
2012-02-11 01:33:11 UTC (rev 6499)
+++ trunk/JLanguageTool/src/test/org/languagetool/tools/StringToolsTest.java    
2012-02-11 01:57:45 UTC (rev 6500)
@@ -167,6 +167,22 @@
         "</matches>\n", xml);
   }
 
+  public void testRuleMatchesToXMLEscapeBug() throws IOException {
+    final List<RuleMatch> matches = new ArrayList<RuleMatch>();
+    final String text = "This is \"an test sentence. Here's another sentence 
with more text.";
+    final RuleMatch match = new RuleMatch(new AvsAnRule(null), 9, 11, 
"myMessage");
+    match.setColumn(99);
+    match.setEndColumn(100);
+    match.setLine(44);
+    match.setEndLine(45);
+    matches.add(match);
+    final String xml = StringTools.ruleMatchesToXML(matches, text, 5, 
StringTools.XmlPrintMode.NORMAL_XML);
+    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+        "<matches>\n" +
+        "<error fromy=\"44\" fromx=\"98\" toy=\"45\" tox=\"99\" 
ruleId=\"EN_A_VS_AN\" msg=\"myMessage\" replacements=\"\" context=\"... is 
&quot;an test...\" contextoffset=\"8\" errorlength=\"2\"/>\n" +
+        "</matches>\n", xml);
+  }
+
   public void testListToString() {
     final List<String> list = new ArrayList<String>();
     list.add("foo");

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to