I have a servlet that I use to search the JCR based on a user-provided query. I log the string that is to be used as the query before running it. However, I get a parse error when running the query and the error shows a differently formatted query than the string logged. Am I doing something wrong or is there a bug in the stack that parses/formats the query? Below is a servlet that should produce the error and the log messages I get. The query used is "ma'a salama". req below is the object from SlingHttpServletRequest in the servlet's doGet method.
/jcr:root/content/sample/en/home/academics/divisions//*[@sling:resourceType='sample/components/page/person-bio' and (jcr:like(fn:lower-case(title), '%ma'a(*)%salama%') or jcr:like(fn:lower-case(bioinfo), '%ma'a%salama%'))]; expected: )
Notice how in the query in the error statement has (*) inserted in the middle. Can anyone shed some light on this? I am using AEM 6.2 with CFP 18.
I believe that escaping simply converts ' to \' (adds a backslash) and then we require replace to make it double because it is xpath query. I can check the API and validate later or may be do a simple test and print it in logs..
That resolved the issue, thanks. I found the function to escape illegal characters from that exact page, but I was not sure why I would need to to replace characters if they were properly escaped in the first place. The document doesn't discuss why the replaceAll is there after either. A little odd. Now, however, the query contains:
I would agree but I do escape it, using org.apache.jackrabbit.util.Text.escapeIllegalXpathSearchChars. I have also tried Text.escapeIllegalJcrChars. Is there no existing function to escape the query automatically or do I have to write something?