jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r799550 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
Date Fri, 31 Jul 2009 09:00:16 GMT
Author: mreutegg
Date: Fri Jul 31 09:00:15 2009
New Revision: 799550

URL: http://svn.apache.org/viewvc?rev=799550&view=rev
Log:
JCR-2236: Malformed excerpt if content contains markup and no highlights found

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java?rev=799550&r1=799549&r2=799550&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
Fri Jul 31 09:00:15 2009
@@ -379,16 +379,18 @@
         int min = excerpt.length();
         char[] buf = new char[maxLength];
         int len = reader.read(buf);
-        excerpt.append(buf, 0, len);
+        StringBuffer tmp = new StringBuffer();
+        tmp.append(buf, 0, len);
         if (len == buf.length) {
-            for (int i = excerpt.length() - 1; i > min; i--) {
-                if (Character.isWhitespace(excerpt.charAt(i))) {
-                    excerpt.delete(i, excerpt.length());
-                    excerpt.append(" ...");
+            for (int i = tmp.length() - 1; i > min; i--) {
+                if (Character.isWhitespace(tmp.charAt(i))) {
+                    tmp.delete(i, tmp.length());
+                    tmp.append(" ...");
                     break;
                 }
             }
         }
+        excerpt.append(Text.encodeIllegalXMLCharacters(tmp.toString()));
         excerpt.append(fragmentEnd).append(excerptEnd);
         return excerpt.toString();
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java?rev=799550&r1=799549&r2=799550&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
Fri Jul 31 09:00:15 2009
@@ -104,6 +104,21 @@
                 "apache jackrabbit");
     }
 
+    public void testEncodeIllegalCharsNoHighlights() throws RepositoryException {
+        String text = "bla <strong>bla</strong> bla";
+        String excerpt = createExcerpt("bla &lt;strong&gt;bla&lt;/strong&gt;
bla");
+        Node n = testRootNode.addNode(nodeName1);
+        n.setProperty("text", text);
+        n.setProperty("other", "foo");
+        superuser.save();
+
+        String stmt = getStatement("foo");
+        QueryResult result = executeQuery(stmt);
+        RowIterator rows = result.getRows();
+        assertEquals(1, rows.getSize());
+        assertEquals(excerpt, rows.nextRow().getValue("rep:excerpt(text)").getString());
+    }
+
     private void checkExcerpt(String text, String fragmentText, String terms)
             throws RepositoryException {
         String excerpt = createExcerpt(fragmentText);



Mime
View raw message