Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ public XQueryContext(final XQueryContext copyFrom) {
LOG.warn("Failed to copy namespace declaration for prefix '{}'", prefix, ex);
}
}

// Copy in-scope namespaces registered via declareInScopeNamespace. Otherwise QName.parse()
// will raise error XPST0081 when resolving path-step names in any of those.
for (final Map.Entry<String, String> entry : copyFrom.inScopeNamespaces.entrySet()) {
inScopeNamespaces.put(entry.getKey(), entry.getValue());
inScopePrefixes.put(entry.getValue(), entry.getKey());
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* eXist-db Open Source Native XML Database
* Copyright (C) 2001 The eXist-db Authors
*
* info@exist-db.org
* http://www.exist-db.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.exist.xquery;

import java.io.StringReader;

import org.exist.EXistException;
import org.exist.security.PermissionDeniedException;
import org.exist.storage.BrokerPool;
import org.exist.test.ExistEmbeddedServer;
import org.exist.xquery.parser.XQueryLexer;
import org.exist.xquery.parser.XQueryParser;
import org.exist.xquery.parser.XQueryTreeParser;

import antlr.collections.AST;

import org.junit.ClassRule;
import org.junit.Test;

/**
* Verifies that namespaces registered on the static context via
* {@link XQueryContext#declareInScopeNamespace(String, String)} before
* compilation are visible to path-step QName resolution. The XQTS runner
* relies on this to apply &lt;environment&gt;/&lt;namespace&gt; declarations
* (e.g. the "atomic" environment) without rewriting test queries.
*
* <p>Regression test for set-operator XPST0081 failures discovered in the
* XQ 3.1 develop gap analysis (op-intersect, op-union, op-except).
*/
public class InScopeNamespaceCompileTest {

@ClassRule
public static final ExistEmbeddedServer server = new ExistEmbeddedServer(true, true);

private static final String ATOMIC_NS = "http://www.w3.org/XQueryTest";

private void compileWithAtomicPrefix(final String query) throws Exception {
final BrokerPool pool = BrokerPool.getInstance();
final XQueryContext context = new XQueryContext(pool);
context.declareInScopeNamespace("atomic", ATOMIC_NS);

final XQueryLexer lexer = new XQueryLexer(context, new StringReader(query));
final XQueryParser xparser = new XQueryParser(lexer);
xparser.xpath();
if (xparser.foundErrors()) {
throw new AssertionError(xparser.getErrorMessage());
}
final AST ast = xparser.getAST();
final XQueryTreeParser treeParser = new XQueryTreeParser(context);
final PathExpr expr = new PathExpr(context);
treeParser.xpath(ast, expr);
if (treeParser.foundErrors()) {
throw new AssertionError(treeParser.getErrorMessage());
}
}

@Test
public void intersectResolvesPrefix()

Check warning on line 77 in exist-core/src/test/java/org/exist/xquery/InScopeNamespaceCompileTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

exist-core/src/test/java/org/exist/xquery/InScopeNamespaceCompileTest.java#L77

JUnit tests should include assert() or fail()
throws EXistException, PermissionDeniedException, Exception {
// mirrors XQTS fn-intersect-node-args-016
compileWithAtomicPrefix("(/atomic:root/atomic:integer) intersect (/atomic:root/atomic:integer)");
}

@Test
public void unionResolvesPrefix() throws Exception {

Check warning on line 84 in exist-core/src/test/java/org/exist/xquery/InScopeNamespaceCompileTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

exist-core/src/test/java/org/exist/xquery/InScopeNamespaceCompileTest.java#L84

JUnit tests should include assert() or fail()
// mirrors XQTS fn-union-node-args-016
compileWithAtomicPrefix("(/atomic:root/atomic:integer) union (/atomic:root/atomic:integer)");
}

@Test
public void exceptResolvesPrefix() throws Exception {

Check warning on line 90 in exist-core/src/test/java/org/exist/xquery/InScopeNamespaceCompileTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

exist-core/src/test/java/org/exist/xquery/InScopeNamespaceCompileTest.java#L90

JUnit tests should include assert() or fail()
// mirrors XQTS fn-except-node-args-016
compileWithAtomicPrefix("(/atomic:root/atomic:integer) except (/atomic:root/atomic:integer)");
}

@Test
public void plainPathResolvesPrefix() throws Exception {

Check warning on line 96 in exist-core/src/test/java/org/exist/xquery/InScopeNamespaceCompileTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

exist-core/src/test/java/org/exist/xquery/InScopeNamespaceCompileTest.java#L96

JUnit tests should include assert() or fail()
// baseline: a plain path expression must work too
compileWithAtomicPrefix("/atomic:root/atomic:integer");
}
}
Loading