Skip to content

Commit b555e1c

Browse files
committed
[bugfix] Ensure backwards compatibility with eXist-db URL Rewrite Controllers (controller.xq) that use exist: variables but do not declare them as external variables
1 parent cfcae5e commit b555e1c

File tree

6 files changed

+75
-11
lines changed

6 files changed

+75
-11
lines changed

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@
11341134
<include>src/main/java/org/exist/xquery/Variable.java</include>
11351135
<include>src/main/java/org/exist/xquery/VariableDeclaration.java</include>
11361136
<include>src/main/java/org/exist/xquery/VariableImpl.java</include>
1137+
<include>src/main/java/org/exist/xquery/VariableReference.java</include>
11371138
<include>src/test/java/org/exist/xquery/WindowClauseTest.java</include>
11381139
<include>src/test/java/org/exist/xquery/XmldbBinariesTest.java</include>
11391140
<include>src/test/java/org/exist/xquery/XPathQueryTest.java</include>
@@ -1805,6 +1806,7 @@
18051806
<exclude>src/main/java/org/exist/xquery/Variable.java</exclude>
18061807
<exclude>src/main/java/org/exist/xquery/VariableDeclaration.java</exclude>
18071808
<exclude>src/main/java/org/exist/xquery/VariableImpl.java</exclude>
1809+
<exclude>src/main/java/org/exist/xquery/VariableReference.java</exclude>
18081810
<exclude>src/test/java/org/exist/xquery/WatchdogTest.java</exclude>
18091811
<exclude>src/test/java/org/exist/xquery/WindowClauseTest.java</exclude>
18101812
<exclude>src/test/java/org/exist/xquery/XmldbBinariesTest.java</exclude>

exist-core/src/main/java/org/exist/xquery/VariableReference.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -21,6 +45,7 @@
2145
*/
2246
package org.exist.xquery;
2347

48+
import org.exist.Namespaces;
2449
import org.exist.dom.QName;
2550
import org.exist.dom.persistent.DocumentSet;
2651
import org.exist.xquery.util.ExpressionDumper;
@@ -59,16 +84,22 @@ public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException
5984
// ignore: variable might not be known yet
6085
return;
6186
}
62-
if (var == null) {
87+
88+
// TODO(AR) this `if` guard statement is a workaround for controller.xq files that use controller variables (e.g. exist:path) but do not declare them as external
89+
if (var == null && !Namespaces.EXIST_NS.equals(qname.getNamespaceURI())) {
6390
throw new XPathException(this, ErrorCodes.XPST0008,
64-
"Variable '$" + qname + "' is not declared.");
91+
"Variable '$" + qname + "' is not declared.");
6592
}
66-
if (!var.isInitialized()) {
93+
94+
if (var != null && !var.isInitialized()) {
6795
throw new XPathException(this, ErrorCodes.XQST0054,
68-
"variable declaration of '$" + qname + "' cannot " +
69-
"be executed because of a circularity.");
96+
"variable declaration of '$" + qname + "' cannot " +
97+
"be executed because of a circularity.");
98+
}
99+
100+
if (var != null) {
101+
contextInfo.setStaticReturnType(var.getStaticType());
70102
}
71-
contextInfo.setStaticReturnType(var.getStaticType());
72103
}
73104

74105
@Override

exist-jetty-config/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<includes>
105105
<include>pom.xml</include>
106106
<include>src/main/resources/org/exist/jetty/etc/webapps/portal/index.html</include>
107-
<include>src/main/resources/webapp/controller.xql</include>
107+
<include>src/main/resources/webapp/controller.xq</include>
108108
<include>src/main/resources/webapp/404.html</include>
109109
</includes>
110110
</licenseSet>

exist-jetty-config/src/main/resources/webapp/controller.xql renamed to exist-jetty-config/src/main/resources/webapp/controller.xq

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ xquery version "3.0";
5252
sub-controllers.
5353
------------------------------------------------------- :)
5454

55-
declare namespace c="http://exist-db.org/xquery/controller";
56-
declare namespace expath="http://expath.org/ns/pkg";
55+
declare namespace exist = "http://exist.sourceforge.net/NS/exist";
56+
declare namespace expath = "http://expath.org/ns/pkg";
5757

58-
import module namespace request="http://exist-db.org/xquery/request";
59-
import module namespace xdb = "http://exist-db.org/xquery/xmldb";
58+
import module namespace repo = "http://exist-db.org/xquery/repo";
59+
import module namespace request = "http://exist-db.org/xquery/request";
60+
import module namespace util = "http://exist-db.org/xquery/util";
61+
62+
declare variable $exist:path external;
6063

6164
declare function local:get-dashboard() {
6265
let $path := collection(repo:get-root())//expath:package[@name = "http://exist-db.org/apps/dashboard"]

extensions/modules/expathrepo/expathrepo-trigger-test/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
<include>pom.xml</include>
180180
<include>src/main/java/org/exist/repo/ExampleModule.java</include>
181181
<include>src/test/resources/conf.xml</include>
182+
<include>src/main/xar-resources/controller.xq</include>
182183
<include>xar-assembly.xml</include>
183184
</includes>
184185
</licenseSet>
@@ -192,6 +193,7 @@
192193
<exclude>pom.xml</exclude>
193194
<exclude>src/main/java/org/exist/repo/ExampleModule.java</exclude>
194195
<exclude>src/test/resources/conf.xml</exclude>
196+
<exclude>src/main/xar-resources/controller.xq</exclude>
195197
<exclude>xar-assembly.xml</exclude>
196198
</excludes>
197199
</licenseSet>

extensions/modules/expathrepo/expathrepo-trigger-test/src/main/xar-resources/controller.xql renamed to extensions/modules/expathrepo/expathrepo-trigger-test/src/main/xar-resources/controller.xq

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
(:
2+
: Elemental
3+
: Copyright (C) 2024, Evolved Binary Ltd
4+
:
5+
6+
: https://www.evolvedbinary.com | https://www.elemental.xyz
7+
:
8+
: This library is free software; you can redistribute it and/or
9+
: modify it under the terms of the GNU Lesser General Public
10+
: License as published by the Free Software Foundation; version 2.1.
11+
:
12+
: This library is distributed in the hope that it will be useful,
13+
: but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
: Lesser General Public License for more details.
16+
:
17+
: You should have received a copy of the GNU Lesser General Public
18+
: License along with this library; if not, write to the Free Software
19+
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
:
21+
: NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
: The original license header is included below.
23+
:
24+
: =====================================================================
25+
:
226
: eXist-db Open Source Native XML Database
327
: Copyright (C) 2001 The eXist-db Authors
428
:
@@ -23,6 +47,8 @@ xquery version "3.1";
2347

2448
declare namespace exist = "http://exist.sourceforge.net/NS/exist";
2549

50+
import module namespace request = "http://exist-db.org/xquery/request";
51+
2652
declare variable $exist:path external;
2753
declare variable $exist:resource external;
2854
declare variable $exist:controller external;

0 commit comments

Comments
 (0)