jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Reutegger <marcel.reuteg...@gmx.net>
Subject Re: escape characters in search/query expression
Date Tue, 28 Aug 2007 10:11:22 GMT
bilobag wrote:
> I see in the JCR spec - it states that {', ", -, \} must be escaped
> by a "\".  However when I try to escape a single quote with a backslash, the
> query throws an xpath query syntax error.  Is the JCR spec correct or is
> there other documentation about what characters need to be escaped?  I am
> already using the ISO9075 class to encode any node paths in my query.  It
> would be even better if there is already a method that escapes search
> strings.  The following is the query that fails.  I am trying to pass the
> string "test's" into the contains(), but when i escape the single quote with
> a backslash, the query throws a sytax error.  
> /jcr:root/app_x0020_root//*[@jcr:primaryType = 'cwe:file' and 
> jcr:contains(jcr:content, 'test\'s')]/(rep:excerpt()) order by @jcr:score
> descending

there are alway to escape mechanisms you have to keep in mind.

1) escaping a character within the contains statement. e.g. the spec says you 
can search for a phrase using double quotes: "foo bar". that means if you want 
to use a double quote as literal an not a delimiter for a phrase you have to 
escape it.

2) escaping any string literal appropriately in XPath or SQL. E.g. in XPath the 
string literal test's must be written as: 'test''s'

for your query that means you have to write:

/jcr:root/app_x0020_root//*[@jcr:primaryType = 'cwe:file' and
  jcr:contains(jcr:content, 'test\''s')]/(rep:excerpt()) order by @jcr:score


View raw message