From: <fg...@us...> - 2011-01-02 10:47:18
|
Revision: 3206 http://openutils.svn.sourceforge.net/openutils/?rev=3206&view=rev Author: fgiust Date: 2011-01-02 10:47:12 +0000 (Sun, 02 Jan 2011) Log Message: ----------- CRIT-31 Escaping of whitespace in base path should not affect xpath conditions Modified Paths: -------------- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathWithSpacesTest.java Modified: trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java =================================================================== --- trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2011-01-02 10:22:28 UTC (rev 3205) +++ trunk/openutils-mgnlcriteria/src/main/java/net/sourceforge/openutils/mgnlcriteria/jcr/query/xpath/utils/XPathTextUtils.java 2011-01-02 10:47:12 UTC (rev 3206) @@ -107,6 +107,9 @@ } StringBuilder encodedPath = new StringBuilder(path.length()); + + boolean inXpathCondition = false; + // TODO maybe a more robust check is needed for (int i = 0; i < path.length(); ++i) { @@ -116,12 +119,21 @@ { encodedPath.append("_x" + StringUtils.leftPad(Integer.toHexString(ch), 4, '0') + "_"); } - else if (ch == ' ') + else if (!inXpathCondition && ch == ' ') { encodedPath.append("_x0020_"); } else { + + if (ch == '[') + { + inXpathCondition = true; + } + else if (inXpathCondition && ch == ']') + { + inXpathCondition = false; + } encodedPath.append(ch); } } Modified: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathWithSpacesTest.java =================================================================== --- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathWithSpacesTest.java 2011-01-02 10:22:28 UTC (rev 3205) +++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/BasePathWithSpacesTest.java 2011-01-02 10:47:12 UTC (rev 3206) @@ -74,4 +74,20 @@ Assert.assertEquals(items.next().getName(), "consectetur adipisici elit"); } + /** + * @throws Exception + */ + @Test + public void testWithParams() throws Exception + { + Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(ContentRepository.WEBSITE); + criteria.setBasePath("//*[prop1='A' and prop2='B']/Lorem ipsum dolor sit amet"); + criteria.add(Restrictions.eq(Criterion.JCR_PRIMARYTYPE, "mgnl:content")); + AdvancedResult advResult = criteria.execute(); + + // if not escaped properly it will crash + Assert.assertEquals(advResult.getTotalSize(), 0); + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |