[338494] [xpath2] prohibiting xpath expressions starting with / or // to be parsed
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AbstractPsychoPathTest.java b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AbstractPsychoPathTest.java
index bdf94bb..73586b5 100644
--- a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AbstractPsychoPathTest.java
+++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/AbstractPsychoPathTest.java
@@ -15,6 +15,7 @@
* Jesper S Moller - bug 275610 - Avoid big time and memory overhead for externals
* Jesper Steen Moeller - bug 282096 - make test harness handle all string encoding
* Jesper Steen Moller - bug 280555 - Add pluggable collation support
+ * Mukul Gandhi - bug 338494 - prohibiting xpath expressions starting with / or // to be parsed.
*******************************************************************************/
package org.eclipse.wst.xml.xpath2.processor.test;
@@ -277,8 +278,7 @@
dynamicContext.add_namespace(null, uri);
}
- protected XPath compileXPath(DynamicContext dc, String xpath)
- throws XPathParserException, StaticError {
+ protected XPath compileXPath(DynamicContext dc, String xpath) throws XPathParserException, StaticError {
XPathParser xpp = new JFlexCupParser();
XPath path = xpp.parse(xpath);
@@ -286,6 +286,21 @@
name_check.check(path);
return path;
}
+
+ protected XPath compileXPath(DynamicContext dc, String xpath, boolean isRootlessAccess) throws XPathParserException, StaticError {
+ XPathParser xpp = new JFlexCupParser();
+ XPath path = null;
+ if (isRootlessAccess) {
+ path = xpp.parse(xpath, isRootlessAccess);
+ }
+ else {
+ path = xpp.parse(xpath);
+ }
+
+ StaticChecker name_check = new StaticNameResolver(dc);
+ name_check.check(path);
+ return path;
+ }
protected String getExpectedResult(String xqFile) {
return getExpectedResult(xqFile, true);
diff --git a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/TestBugs.java b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/TestBugs.java
index 04617c7..ad647c5 100644
--- a/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/TestBugs.java
+++ b/tests/org.eclipse.wst.xml.xpath2.processor.tests/src/org/eclipse/wst/xml/xpath2/processor/test/TestBugs.java
@@ -49,7 +49,8 @@
* an user-defined variable.
* Mukul Gandhi - bug 334478 implementation of xs:token data type
* Mukul Gandhi - bug 334842 - improving support for the data types Name, NCName, ENTITY,
- * ID, IDREF and NMTOKEN.
+ * ID, IDREF and NMTOKEN.
+ * Mukul Gandhi - bug 338494 - prohibiting xpath expressions starting with / or // to be parsed.
*******************************************************************************/
package org.eclipse.wst.xml.xpath2.processor.test;
@@ -70,6 +71,7 @@
import org.eclipse.wst.xml.xpath2.processor.Evaluator;
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
+import org.eclipse.wst.xml.xpath2.processor.XPathParserException;
import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
import org.eclipse.wst.xml.xpath2.processor.internal.types.QName;
import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean;
@@ -97,6 +99,7 @@
}
+
public void testNamesWhichAreKeywords() throws Exception {
// Bug 273719
URL fileURL = bundle.getEntry("/bugTestFiles/bug311480.xml");
@@ -2038,6 +2041,113 @@
assertEquals("true", result.string_value());
}
+ public void testBugXX() throws Exception {
+ bundle = Platform.getBundle("org.w3c.xqts.testsuite");
+ URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ // set up XPath default namespace in Dynamic Context
+ DynamicContext dc = setupDynamicContext(schema);
+ dc.set_variable(new QName("value"), new XSString("2.5"));
+ addXPathDefaultNamespace("http://www.w3.org/2001/XMLSchema");
+
+ String xpath = "$value castable as double";
+ XPath path = compileXPath(dc, xpath);
+
+ Evaluator eval = new DefaultEvaluator(dc, null);
+ ResultSequence rs = eval.evaluate(path);
+
+ XSBoolean result = (XSBoolean) rs.first();
+
+ String actual = result.string_value();
+
+ assertEquals("true", actual);
+ }
+
+ public void testExprParsingBeginnigWithRootNode_bugXX() throws Exception {
+ // Bug ??
+ bundle = Platform.getBundle("org.w3c.xqts.testsuite");
+ URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
+ loadDOMDocument(fileURL);
+
+ // Get XML Schema Information for the Document
+ XSModel schema = getGrammar();
+
+ DynamicContext dc = setupDynamicContext(schema);
+
+ // test a)
+ String xpath = "/x";
+ XPath path = null;
+ try {
+ path = compileXPath(dc, xpath, true);
+ // test fails
+ assertTrue(false);
+ }
+ catch(XPathParserException ex) {
+ if ("Expression starts with / or //".equals(ex.getMessage())) {
+ // test passes
+ assertTrue(true);
+ }
+ }
+
+ // test b)
+ xpath = "//x";
+ try {
+ path = compileXPath(dc, xpath, true);
+ // test fails
+ assertTrue(false);
+ }
+ catch(XPathParserException ex) {
+ if ("Expression starts with / or //".equals(ex.getMessage())) {
+ // test passes
+ assertTrue(true);
+ }
+ }
+
+ // test c)
+ xpath = "/";
+ try {
+ path = compileXPath(dc, xpath, true);
+ // test fails
+ assertTrue(false);
+ }
+ catch(XPathParserException ex) {
+ if ("Expression starts with / or //".equals(ex.getMessage())) {
+ // test passes
+ assertTrue(true);
+ }
+ }
+
+ // test d)
+ xpath = "x/y[/a]";
+ try {
+ path = compileXPath(dc, xpath, true);
+ // test fails
+ assertTrue(false);
+ }
+ catch(XPathParserException ex) {
+ if ("Expression starts with / or //".equals(ex.getMessage())) {
+ // test passes
+ assertTrue(true);
+ }
+ }
+
+ // test e)
+ xpath = ".//x";
+ try {
+ path = compileXPath(dc, xpath, true);
+ // test passes
+ assertTrue(true);
+ }
+ catch(XPathParserException ex) {
+ // test fails
+ assertTrue(false);
+ }
+ }
+
private CollationProvider createLengthCollatorProvider() {
return new CollationProvider() {
@SuppressWarnings("unchecked")