Skip to content

Commit b71a329

Browse files
committed
[bugfix] Processing Instruction persistent DOM nodes must return their target as their node name
Closes eXist-db/exist#5923
1 parent a33e34e commit b71a329

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@
740740
<header>${project.parent.relativePath}/../elemental-parent/elemental-LGPL-21-ONLY-license.template.txt</header>
741741
<includes>
742742
<include>project-suppression.xml</include>
743+
<include>src/test/xquery/pi.xqm</include>
743744
<include>src/test/xquery/securitymanager/acl.xqm</include>
744745
<include>src/main/java/org/exist/dom/memtree/DocumentTypeImpl.java</include>
745746
<include>src/main/java/org/exist/dom/memtree/reference/AbstractReferenceCharacterData.java</include>
@@ -1228,6 +1229,7 @@
12281229
<exclude>src/test/xquery/instance-of.xqm</exclude>
12291230
<exclude>src/test/xquery/operator-mapping.xqm</exclude>
12301231
<exclude>src/test/xquery/order.xqm</exclude>
1232+
<exclude>src/test/xquery/pi.xqm</exclude>
12311233
<exclude>src/test/xquery/tail-recursion.xml</exclude>
12321234
<exclude>src/test/xquery/type-promotion.xqm</exclude>
12331235
<exclude>src/test/xquery/maps/maps.xqm</exclude>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*/
4646
package org.exist.dom.persistent;
4747

48+
import org.exist.dom.QName;
4849
import org.exist.numbering.NodeId;
4950
import org.exist.storage.Signatures;
5051
import org.exist.util.ByteConversion;
@@ -61,7 +62,7 @@
6162
*
6263
* @author wolf
6364
*/
64-
public class ProcessingInstructionImpl extends StoredNode<ProcessingInstructionImpl> implements ProcessingInstruction {
65+
public class ProcessingInstructionImpl extends NamedNode<ProcessingInstructionImpl> implements ProcessingInstruction {
6566

6667
public static final int LENGTH_TARGET_DATA = 4; //Sizeof int;
6768

@@ -81,7 +82,7 @@ public ProcessingInstructionImpl(final NodeId nodeId, final String target, final
8182
}
8283

8384
public ProcessingInstructionImpl(final Expression expression, final NodeId nodeId, final String target, final String data) {
84-
super(expression, Node.PROCESSING_INSTRUCTION_NODE, nodeId);
85+
super(expression, Node.PROCESSING_INSTRUCTION_NODE, nodeId, new QName(target, null));
8586
this.target = target;
8687
this.data = data;
8788
}
@@ -98,6 +99,7 @@ public ProcessingInstructionImpl(final Expression expression, final String targe
9899
public void clear() {
99100
super.clear();
100101
target = null;
102+
setQName(null);
101103
data = null;
102104
}
103105

@@ -118,6 +120,7 @@ public String getTarget() {
118120
*/
119121
public void setTarget(final String target) {
120122
this.target = target;
123+
setQName(new QName(target, null));
121124
}
122125

123126
@Override

exist-core/src/test/xquery/pi.xqm

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
(:
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+
xquery version "3.0";
22+
23+
(:~
24+
: Tests for Processing Instruction nodes.
25+
:
26+
: @author Adam Retter
27+
:)
28+
module namespace pi = "http://exist-db.org/xquery/test/pi";
29+
30+
import module namespace test = "http://exist-db.org/xquery/xqsuite";
31+
32+
declare %private variable $pi:doc1 := document {
33+
<?my-pi my-pi-content ?>,
34+
<x/>
35+
};
36+
37+
declare
38+
%test:setUp
39+
function pi:setup() {
40+
let $test-collection := xmldb:create-collection("/db", "pi-test")
41+
return
42+
xmldb:store($test-collection, "doc1.xml", $pi:doc1)
43+
};
44+
45+
declare
46+
%test:tearDown
47+
function pi:tearDown() {
48+
xmldb:remove("/db/pi-test")
49+
};
50+
51+
declare
52+
%test:assertEquals("my-pi")
53+
function pi:in-memory-dom-pi-name() {
54+
$pi:doc1/processing-instruction()/name()
55+
};
56+
57+
declare
58+
%test:assertEquals("my-pi")
59+
function pi:persistent-dom-pi-name() {
60+
doc("/db/pi-test/doc1.xml")/processing-instruction()/name()
61+
};

0 commit comments

Comments
 (0)