Skip to content

Commit f02f867

Browse files
authored
Merge pull request #221 from evolvedbinary/6.x.x/hotfix/base-uri-as-uri
[6.x.x] BaseURI is now a valid URI
2 parents d5ff9f6 + a7070b3 commit f02f867

22 files changed

Lines changed: 562 additions & 46 deletions

File tree

exist-core/pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@
780780
<include>src/test/xquery/base-uri.xql</include>
781781
<include>src/test/xquery/parenthesizedLocationStep.xml</include>
782782
<include>src/test/xquery/tail-recursion.xml</include>
783+
<include>src/test/xquery/indexing/indexes-base-uri.xq</include>
783784
<include>src/test/xquery/maps/maps.xqm</include>
784785
<include>src/test/xquery/numbers/format-numbers.xql</include>
785786
<include>src/test/xquery/util/util.xml</include>
@@ -865,6 +866,7 @@
865866
<include>src/main/java/org/exist/dom/QName.java</include>
866867
<include>src/main/java/org/exist/dom/memtree/AbstractCharacterData.java</include>
867868
<include>src/main/java/org/exist/dom/memtree/AttrImpl.java</include>
869+
<include>src/main/java/org/exist/dom/memtree/CDATASectionImpl.java</include>
868870
<include>src/main/java/org/exist/dom/memtree/CommentImpl.java</include>
869871
<include>src/main/java/org/exist/dom/memtree/DocumentBuilderReceiver.java</include>
870872
<include>src/main/java/org/exist/dom/memtree/DocumentImpl.java</include>
@@ -884,6 +886,7 @@
884886
<include>src/test/java/org/exist/dom/persistent/BasicNodeSetTest.java</include>
885887
<include>src/main/java/org/exist/dom/persistent/BinaryDocument.java</include>
886888
<include>src/test/java/org/exist/dom/persistent/CDataIntergationTest.java</include>
889+
<include>src/main/java/org/exist/dom/persistent/CDATASectionImpl.java</include>
887890
<include>src/main/java/org/exist/dom/persistent/CommentImpl.java</include>
888891
<include>src/test/java/org/exist/dom/persistent/CommentTest.java</include>
889892
<include>src/test/java/org/exist/dom/persistent/DefaultDocumentSetTest.java</include>
@@ -1086,6 +1089,7 @@
10861089
<include>src/test/java/org/exist/util/CollationsTest.java</include>
10871090
<include>src/main/java/org/exist/util/Configuration.java</include>
10881091
<include>src/test/java/org/exist/util/DOMSerializerTest.java</include>
1092+
<include>src/main/java/org/exist/util/EXistURISchemeURIResolver.java</include>
10891093
<include>src/test/java/org/exist/util/LeasableTest.java</include>
10901094
<include>src/test/java/org/exist/util/MediaTypeResolverTest.java</include>
10911095
<include>src/main/java/org/exist/util/MimeTable.java</include>
@@ -1347,6 +1351,7 @@
13471351
<include>src/main/java/org/exist/xquery/functions/fn/transform/Options.java</include>
13481352
<include>src/main/java/org/exist/xquery/functions/fn/transform/Transform.java</include>
13491353
<include>src/main/java/org/exist/xquery/functions/fn/transform/TreeUtils.java</include>
1354+
<include>src/main/java/org/exist/xquery/functions/fn/transform/URIResolution.java</include>
13501355
<include>src/test/java/org/exist/xquery/functions/inspect/InspectModuleTest.java</include>
13511356
<include>src/main/java/org/exist/xquery/functions/integer/WordPicture.java</include>
13521357
<include>src/main/java/org/exist/xquery/functions/map/MapExpr.java</include>
@@ -1390,6 +1395,7 @@
13901395
<include>src/test/java/org/exist/xquery/functions/validate/JingSchematronTest.java</include>
13911396
<include>src/test/java/org/exist/xquery/functions/validate/JingXsdTest.java</include>
13921397
<include>src/main/java/org/exist/xquery/functions/validation/Jaxp.java</include>
1398+
<include>src/main/java/org/exist/xquery/functions/validation/Shared.java</include>
13931399
<include>src/test/java/org/exist/xquery/functions/xmldb/DbStore2Test.java</include>
13941400
<include>src/main/java/org/exist/xquery/functions/xmldb/XMLDBGetMimeType.java</include>
13951401
<include>src/main/java/org/exist/xquery/functions/xmldb/XMLDBLoadFromPattern.java</include>
@@ -1491,6 +1497,7 @@
14911497
<exclude>src/test/xquery/parenthesizedLocationStep.xml</exclude>
14921498
<exclude>src/test/xquery/pi.xqm</exclude>
14931499
<exclude>src/test/xquery/tail-recursion.xml</exclude>
1500+
<exclude>src/test/xquery/indexing/indexes-base-uri.xq</exclude>
14941501
<exclude>src/test/xquery/maps/maps.xqm</exclude>
14951502
<exclude>src/test/xquery/numbers/format-numbers.xql</exclude>
14961503
<exclude>src/test/xquery/securitymanager/acl.xqm</exclude>
@@ -1578,7 +1585,8 @@
15781585
<exclude>src/main/java/org/exist/dom/QName.java</exclude>
15791586
<exclude>src/main/java/org/exist/dom/memtree/AbstractCharacterData.java</exclude>
15801587
<exclude>src/main/java/org/exist/dom/memtree/AttrImpl.java</exclude>
1581-
<include>src/main/java/org/exist/dom/memtree/CommentImpl.java</include>
1588+
<exclude>src/main/java/org/exist/dom/memtree/CDATASectionImpl.java</exclude>
1589+
<exclude>src/main/java/org/exist/dom/memtree/CommentImpl.java</exclude>
15821590
<exclude>src/main/java/org/exist/dom/memtree/DocumentBuilderReceiver.java</exclude>
15831591
<exclude>src/main/java/org/exist/dom/memtree/DocumentImpl.java</exclude>
15841592
<exclude>src/test/java/org/exist/dom/memtree/DocumentImplTest.java</exclude>
@@ -1605,6 +1613,7 @@
16051613
<exclude>src/test/java/org/exist/dom/persistent/BasicNodeSetTest.java</exclude>
16061614
<exclude>src/main/java/org/exist/dom/persistent/BinaryDocument.java</exclude>
16071615
<exclude>src/test/java/org/exist/dom/persistent/CDataIntergationTest.java</exclude>
1616+
<exclude>src/main/java/org/exist/dom/persistent/CDATASectionImpl.java</exclude>
16081617
<exclude>src/main/java/org/exist/dom/persistent/CommentImpl.java</exclude>
16091618
<exclude>src/test/java/org/exist/dom/persistent/CommentTest.java</exclude>
16101619
<exclude>src/test/java/org/exist/dom/persistent/DefaultDocumentSetTest.java</exclude>
@@ -1870,6 +1879,7 @@
18701879
<exclude>src/test/java/org/exist/util/CollectionOfArrayIteratorTest.java</exclude>
18711880
<exclude>src/main/java/org/exist/util/Configuration.java</exclude>
18721881
<exclude>src/test/java/org/exist/util/DOMSerializerTest.java</exclude>
1882+
<exclude>src/main/java/org/exist/util/EXistURISchemeURIResolver.java</exclude>
18731883
<exclude>src/main/java/org/exist/util/IPUtil.java</exclude>
18741884
<exclude>src/main/java/org/exist/util/JREUtil.java</exclude>
18751885
<exclude>src/test/java/org/exist/util/LeasableTest.java</exclude>
@@ -2163,6 +2173,7 @@
21632173
<exclude>src/main/java/org/exist/xquery/functions/fn/transform/Options.java</exclude>
21642174
<exclude>src/main/java/org/exist/xquery/functions/fn/transform/Transform.java</exclude>
21652175
<exclude>src/main/java/org/exist/xquery/functions/fn/transform/TreeUtils.java</exclude>
2176+
<exclude>src/main/java/org/exist/xquery/functions/fn/transform/URIResolution.java</exclude>
21662177
<exclude>src/test/java/org/exist/xquery/functions/inspect/InspectModuleTest.java</exclude>
21672178
<exclude>src/main/java/org/exist/xquery/functions/integer/WordPicture.java</exclude>
21682179
<exclude>src/main/java/org/exist/xquery/functions/map/MapExpr.java</exclude>
@@ -2213,6 +2224,7 @@
22132224
<exclude>src/test/java/org/exist/xquery/functions/validate/JingSchematronTest.java</exclude>
22142225
<exclude>src/test/java/org/exist/xquery/functions/validate/JingXsdTest.java</exclude>
22152226
<exclude>src/main/java/org/exist/xquery/functions/validation/Jaxp.java</exclude>
2227+
<exclude>src/main/java/org/exist/xquery/functions/validation/Shared.java</exclude>
22162228
<exclude>src/test/java/org/exist/xquery/functions/xmldb/AbstractXMLDBTest.java</exclude>
22172229
<exclude>src/test/java/org/exist/xquery/functions/xmldb/DbStore2Test.java</exclude>
22182230
<exclude>src/test/java/org/exist/xquery/functions/xmldb/XMLDBAuthenticateTest.java</exclude>

exist-core/src/main/java/org/exist/dom/memtree/CDATASectionImpl.java

Lines changed: 36 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+
* admin@evolvedbinary.com
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
*
@@ -25,8 +49,11 @@
2549
import org.exist.xquery.value.Type;
2650
import org.w3c.dom.CDATASection;
2751
import org.w3c.dom.DOMException;
52+
import org.w3c.dom.Node;
2853
import org.w3c.dom.Text;
2954

55+
import javax.annotation.Nullable;
56+
3057

3158
/**
3259
* Represents a CDATA section.
@@ -48,6 +75,15 @@ public int getItemType() {
4875
return Type.CDATA_SECTION;
4976
}
5077

78+
@Override
79+
public @Nullable String getBaseURI() {
80+
@Nullable final Node parent = getParentNode();
81+
if (parent == null) {
82+
return null;
83+
}
84+
return parent.getBaseURI();
85+
}
86+
5187
@Override
5288
public Text splitText(final int offset) throws DOMException {
5389
return null;

exist-core/src/main/java/org/exist/dom/persistent/AttrImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.exist.util.XMLString;
5858
import org.exist.util.pool.NodePool;
5959
import org.exist.util.serializer.AttrList;
60+
import org.exist.xmldb.XmldbURI;
6061
import org.exist.xquery.Expression;
6162
import org.w3c.dom.*;
6263

@@ -434,7 +435,12 @@ public boolean isId() {
434435
public @Nullable String getBaseURI() {
435436
@Nullable final Element e = getOwnerElement();
436437
if (e != null) {
437-
return e.getBaseURI();
438+
@Nullable String strBaseUri = e.getBaseURI();
439+
if (strBaseUri != null && strBaseUri.startsWith("/db/")) {
440+
// Must be a URI!
441+
strBaseUri = XmldbURI.EMBEDDED_SERVER_URI_PREFIX + strBaseUri;
442+
}
443+
return strBaseUri;
438444
}
439445
return null;
440446
}

exist-core/src/main/java/org/exist/dom/persistent/CDATASectionImpl.java

Lines changed: 42 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+
* admin@evolvedbinary.com
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
*
@@ -27,12 +51,15 @@
2751
import org.exist.util.ByteConversion;
2852
import org.exist.util.UTF8;
2953
import org.exist.util.XMLString;
54+
import org.exist.xmldb.XmldbURI;
3055
import org.exist.xquery.Expression;
3156
import org.w3c.dom.CDATASection;
3257
import org.w3c.dom.DOMException;
3358
import org.w3c.dom.Node;
3459
import org.w3c.dom.Text;
3560

61+
import javax.annotation.Nullable;
62+
3663
public class CDATASectionImpl extends AbstractCharacterData implements CDATASection {
3764

3865
public CDATASectionImpl() {
@@ -77,6 +104,20 @@ public CDATASectionImpl(final Expression expression, final String data) {
77104
}
78105

79106
@Override
107+
public @Nullable String getBaseURI() {
108+
@Nullable final Node parent = getParentNode();
109+
if (parent != null) {
110+
@Nullable String strBaseUri = parent.getBaseURI();
111+
if (strBaseUri != null && strBaseUri.startsWith("/db/")) {
112+
// Must be a URI!
113+
strBaseUri = XmldbURI.EMBEDDED_SERVER_URI_PREFIX + strBaseUri;
114+
}
115+
return strBaseUri;
116+
} else {
117+
return null;
118+
}
119+
}
120+
80121
/**
81122
* Serializes a (persistent DOM) CDATA Section to a byte array
82123
*
@@ -94,6 +135,7 @@ public CDATASectionImpl(final Expression expression, final String data) {
94135
* @return the returned byte array after use must be returned to the ByteArrayPool
95136
* by calling {@link ByteArrayPool#releaseByteArray(byte[])}
96137
*/
138+
@Override
97139
public byte[] serialize() {
98140
final int nodeIdLen = nodeId.size();
99141
final byte[] data = ByteArrayPool.getByteArray(LENGTH_SIGNATURE_LENGTH + NodeId.LENGTH_NODE_ID_UNITS +

exist-core/src/main/java/org/exist/dom/persistent/CommentImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.exist.storage.Signatures;
5050
import org.exist.util.ByteConversion;
5151
import org.exist.util.pool.NodePool;
52+
import org.exist.xmldb.XmldbURI;
5253
import org.exist.xquery.Expression;
5354
import org.w3c.dom.Comment;
5455
import org.w3c.dom.Node;
@@ -92,7 +93,12 @@ public String toString() {
9293
public @Nullable String getBaseURI() {
9394
@Nullable final Node parent = getParentNode();
9495
if (parent != null) {
95-
return parent.getBaseURI();
96+
@Nullable String strBaseUri = parent.getBaseURI();
97+
if (strBaseUri != null && strBaseUri.startsWith("/db/")) {
98+
// Must be a URI!
99+
strBaseUri = XmldbURI.EMBEDDED_SERVER_URI_PREFIX + strBaseUri;
100+
}
101+
return strBaseUri;
96102
} else {
97103
return null;
98104
}

exist-core/src/main/java/org/exist/dom/persistent/DocumentImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ public Node renameNode(final Node n, final String namespaceURI, final String qua
15921592

15931593
@Override
15941594
public String getBaseURI() {
1595-
return getURI().toString();
1595+
return XmldbURI.EMBEDDED_SERVER_URI_PREFIX + getURI().getCollectionPath();
15961596
}
15971597

15981598
@Override

exist-core/src/main/java/org/exist/dom/persistent/ElementImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,12 @@ public void setIdAttributeNode(final Attr idAttr, final boolean isId) throws DOM
20212021
public @Nullable String getBaseURI() {
20222022
@Nullable final XmldbURI baseURI = calculateBaseURI();
20232023
if (baseURI != null) {
2024-
return baseURI.toString();
2024+
String strBaseUri = baseURI.toString();
2025+
if (strBaseUri.startsWith("/db/")) {
2026+
// Must be a URI!
2027+
strBaseUri = XmldbURI.EMBEDDED_SERVER_URI_PREFIX + baseURI;
2028+
}
2029+
return strBaseUri;
20252030
}
20262031

20272032
return null;

exist-core/src/main/java/org/exist/dom/persistent/ProcessingInstructionImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.exist.storage.Signatures;
5151
import org.exist.util.ByteConversion;
5252
import org.exist.util.pool.NodePool;
53+
import org.exist.xmldb.XmldbURI;
5354
import org.exist.xquery.Expression;
5455
import org.w3c.dom.DOMException;
5556
import org.w3c.dom.Node;
@@ -154,7 +155,12 @@ public void setData(final String data) {
154155
public @Nullable String getBaseURI() {
155156
@Nullable final StoredNode parent = getParentStoredNode();
156157
if (parent != null) {
157-
return parent.getBaseURI();
158+
@Nullable String strBaseUri = parent.getBaseURI();
159+
if (strBaseUri != null && strBaseUri.startsWith("/db/")) {
160+
// Must be a URI!
161+
strBaseUri = XmldbURI.EMBEDDED_SERVER_URI_PREFIX + strBaseUri;
162+
}
163+
return strBaseUri;
158164
} else {
159165
return getOwnerDocument().getBaseURI();
160166
}

exist-core/src/main/java/org/exist/dom/persistent/TextImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.exist.util.ByteConversion;
5353
import org.exist.util.UTF8;
5454
import org.exist.util.pool.NodePool;
55+
import org.exist.xmldb.XmldbURI;
5556
import org.exist.xquery.Expression;
5657
import org.w3c.dom.DOMException;
5758
import org.w3c.dom.Node;
@@ -180,7 +181,12 @@ public Text splitText(final int offset) throws DOMException {
180181
public @Nullable String getBaseURI() {
181182
@Nullable final Node parent = getParentNode();
182183
if (parent != null) {
183-
return parent.getBaseURI();
184+
@Nullable String strBaseUri = parent.getBaseURI();
185+
if (strBaseUri != null && strBaseUri.startsWith("/db/")) {
186+
// Must be a URI!
187+
strBaseUri = XmldbURI.EMBEDDED_SERVER_URI_PREFIX + strBaseUri;
188+
}
189+
return strBaseUri;
184190
} else {
185191
return null;
186192
}

exist-core/src/main/java/org/exist/util/EXistURISchemeURIResolver.java

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+
* admin@evolvedbinary.com
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
*
@@ -56,6 +80,8 @@ private String rewriteScheme(String uri) {
5680
uri = uri.replace("exist://localhost/db", "/db");
5781
} else if (uri.startsWith("exist://")) {
5882
uri = uri.replace("exist://", "xmldb:exist://");
83+
} else if (uri.startsWith("exist:/")) {
84+
uri = uri.replace("exist:/", "xmldb:exist:///");
5985
}
6086
}
6187

0 commit comments

Comments
 (0)