jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r506382 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/xpath/ main/javacc/xpath/ test/java/org/apache/jackrabbit/core/query/
Date Mon, 12 Feb 2007 09:12:39 GMT
Author: mreutegg
Date: Mon Feb 12 01:12:38 2007
New Revision: 506382

URL: http://svn.apache.org/viewvc?view=rev&rev=506382
Log:
JCR-739: String literal must not interpret entity references

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/XPath.jjt
    jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/strip.xsl
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java?view=diff&rev=506382&r1=506381&r2=506382
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
Mon Feb 12 01:12:38 2007
@@ -666,8 +666,7 @@
      */
     private void assignValue(SimpleNode node, RelationQueryNode queryNode) {
         if (node.getId() == JJTSTRINGLITERAL) {
-            queryNode.setStringValue(unescapeQuotes(
-                    decodePredefinedEntities(node.getValue())));
+            queryNode.setStringValue(unescapeQuotes(node.getValue()));
         } else if (node.getId() == JJTDECIMALLITERAL) {
             queryNode.setDoubleValue(Double.parseDouble(node.getValue()));
         } else if (node.getId() == JJTDOUBLELITERAL) {
@@ -746,9 +745,7 @@
                         SimpleNode literal = (SimpleNode) node.jjtGetChild(2).jjtGetChild(0);
                         if (literal.getId() == JJTSTRINGLITERAL) {
                             TextsearchQueryNode contains = new TextsearchQueryNode(
-                                    queryNode,
-                                    unescapeQuotes(decodePredefinedEntities(
-                                            literal.getValue())));
+                                    queryNode, unescapeQuotes(literal.getValue()));
                             // assign property name
                             SimpleNode path = (SimpleNode) node.jjtGetChild(1);
                             path.jjtAccept(this, contains);
@@ -777,8 +774,7 @@
 
                         SimpleNode literal = (SimpleNode) node.jjtGetChild(2).jjtGetChild(0);
                         if (literal.getId() == JJTSTRINGLITERAL) {
-                            like.setStringValue(unescapeQuotes(
-                                    decodePredefinedEntities(literal.getValue())));
+                            like.setStringValue(unescapeQuotes(literal.getValue()));
                         } else {
                             exceptions.add(new InvalidQueryException("Wrong second argument
type for jcr:like"));
                         }
@@ -860,7 +856,6 @@
                             String value = literal.getValue();
                             // strip quotes
                             value = value.substring(1, value.length() - 1);
-                            value = decodePredefinedEntities(value);
                             if (!value.equals("*")) {
                                 QName name = null;
                                 try {
@@ -1027,57 +1022,5 @@
             value = value.replaceAll("''", "'");
         }
         return value;
-    }
-
-    /**
-     * Decodes a string literal with predefined entities. Predefined entities
-     * are:
-     * <ul>
-     * <li>&amp;lt; : &lt;</li>
-     * <li>&amp;gt; : &gt;</li>
-     * <li>&amp;amp; : &amp;</li>
-     * <li>&amp;quote; : "</li>
-     * <li>&amp;apos; : '</li>
-     * </ul>
-     * @param literal a string literal that may contain predefined entities.
-     * @return the decoded string.
-     * @throws IllegalArgumentException if the string <code>literal</code> is
-     *                                  malformed.
-     */
-    private String decodePredefinedEntities(String literal) throws IllegalArgumentException
{
-        int idx = literal.indexOf('&');
-        if (idx == -1) {
-            return literal;
-        }
-        int endIndex = -1;
-        StringBuffer buf = new StringBuffer();
-        buf.append(literal.substring(0, idx));
-        while (idx != -1) {
-            endIndex = literal.indexOf(';', idx);
-            if (endIndex == -1) {
-                throw new IllegalArgumentException(literal);
-            }
-            String entity = literal.substring(idx + 1, endIndex);
-            if (entity.equals("lt")) {
-                buf.append('<');
-            } else if (entity.equals("gt")) {
-                buf.append('>');
-            } else if (entity.equals("amp")) {
-                buf.append('&');
-            } else if (entity.equals("quot")) {
-                buf.append('"');
-            } else if (entity.equals("apos")) {
-                buf.append('\'');
-            } else {
-                throw new IllegalArgumentException(literal);
-            }
-            idx = literal.indexOf('&', idx + 1);
-            if (idx != -1) {
-                buf.append(literal.substring(endIndex + 1, idx));
-            }
-        }
-        // write remaining
-        buf.append(literal.substring(endIndex + 1));
-        return buf.toString();
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/XPath.jjt
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/XPath.jjt?view=diff&rev=506382&r1=506381&r2=506382
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/XPath.jjt (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/XPath.jjt Mon Feb 12 01:12:38 2007
@@ -285,13 +285,13 @@
 <DEFAULT, OPERATOR>
 TOKEN :
 {
- < StringLiteral : (("\"" ((<PredefinedEntityRef> | <CharRef> | ("\"" "\"")
| ~["\"", "&"]))* "\"") | ("'" ((<PredefinedEntityRef> | <CharRef> | ("'"
"'") | ~["'", "&"]))* "'")) > : OPERATOR
+ < StringLiteral : (("\"" ((("\"" "\"") | ~["\""]))* "\"") | ("'" ((("'" "'") | ~["'"]))*
"'")) > : OPERATOR
 }
 
 <KINDTESTFORPI>
 TOKEN :
 {
- < StringLiteralForKindTest : (("\"" ((<PredefinedEntityRef> | <CharRef> |
("\"" "\"") | ~["\"", "&"]))* "\"") | ("'" ((<PredefinedEntityRef> | <CharRef>
| ("'" "'") | ~["'", "&"]))* "'")) > : KINDTESTFORPI
+ < StringLiteralForKindTest : (("\"" ((("\"" "\"") | ~["\""]))* "\"") | ("'" ((("'" "'")
| ~["'"]))* "'")) > : KINDTESTFORPI
 }
 
 <DEFAULT>
@@ -303,7 +303,7 @@
 <XQUERYVERSION>
 TOKEN :
 {
- < StringLiteralForVersion : (("\"" ((<PredefinedEntityRef> | <CharRef> |
("\"" "\"") | ~["\"", "&"]))* "\"") | ("'" ((<PredefinedEntityRef> | <CharRef>
| ("'" "'") | ~["'", "&"]))* "'")) > : XQUERYVERSION
+ < StringLiteralForVersion : (("\"" ((("\"" "\"") | ~["\""]))* "\"") | ("'" ((("'" "'")
| ~["'"]))* "'")) > : XQUERYVERSION
 }
 
 <XQUERYVERSION>
@@ -321,7 +321,7 @@
 <NAMESPACEDECL, NAMESPACEKEYWORD>
 TOKEN :
 {
- < URLLiteral : (("\"" ((<PredefinedEntityRef> | <CharRef> | ("\"" "\"") |
~["\"", "&"]))* "\"") | ("'" ((<PredefinedEntityRef> | <CharRef> | ("'" "'")
| ~["'", "&"]))* "'")) > : DEFAULT
+ < URLLiteral : (("\"" ((("\"" "\"") | ~["\""]))* "\"") | ("'" ((("'" "'") | ~["'"]))*
"'")) > : DEFAULT
 }
 
 <DEFAULT>

Modified: jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/strip.xsl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/strip.xsl?view=diff&rev=506382&r1=506381&r2=506382
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/strip.xsl (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/javacc/xpath/strip.xsl Mon Feb 12 01:12:38 2007
@@ -28,9 +28,17 @@
                       or contains(@if, $spec1) 
                       or contains(@if, $spec2) 
                       or contains(@if, $spec3)]">
-          <xsl:copy>
-            <xsl:apply-templates select="@*|node()"/>
-          </xsl:copy>        
+          <!--
+              Additional check for StringLiteral token. XQuery 1.0 uses
+              a more restricted version than XPath 2.0. JCR XPath must
+              use the XPath 2.0 variant.
+              See: http://issues.apache.org/jira/browse/JCR-739
+          -->
+          <xsl:if test="not(ancestor::g:token[@name = 'StringLiteral']) or not(@if)">
+            <xsl:copy>
+              <xsl:apply-templates select="@*|node()"/>
+            </xsl:copy>        
+          </xsl:if>
         </xsl:if>
     
   </xsl:template>

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java?view=diff&rev=506382&r1=506381&r2=506382
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/FulltextQueryTest.java
Mon Feb 12 01:12:38 2007
@@ -280,7 +280,7 @@
 
         StringBuffer stmt = new StringBuffer();
         stmt.append("/jcr:root").append(testRoot).append("/*");
-        stmt.append("[jcr:contains(., '").append(Text.encodeIllegalXMLCharacters(statement));
+        stmt.append("[jcr:contains(., '").append(statement);
         stmt.append("')]");
 
         Query q = superuser.getWorkspace().getQueryManager().createQuery(stmt.toString(),
Query.XPATH);



Mime
View raw message