Skip to content

Commit 06b1b66

Browse files
gabriele-tomassettiadamretter
authored andcommitted
[bugfix] Fix issue with attribute not accepting some reserved keywords as valid name
Closes #2381
1 parent 1eef586 commit 06b1b66

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

exist-core/src/main/antlr/org/exist/xquery/parser/XQuery.g

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,6 +2224,12 @@ reservedKeywords returns [String name]
22242224
"map" { name = "map"; }
22252225
|
22262226
"array" { name = "array"; }
2227+
|
2228+
"copy-namespaces" { name = "copy-namespaces"; }
2229+
|
2230+
"empty-sequence" { name = "empty-sequence"; }
2231+
|
2232+
"schema-element" { name = "schema-element"; }
22272233
;
22282234

22292235
/**
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* eXist-db Open Source Native XML Database
3+
* Copyright (C) 2001 The eXist-db Authors
4+
*
5+
6+
* http://www.exist-db.org
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; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
22+
package org.exist.xquery;
23+
24+
import antlr.RecognitionException;
25+
import antlr.TokenStreamException;
26+
import org.exist.xquery.parser.XQueryAST;
27+
import org.exist.xquery.parser.XQueryLexer;
28+
import org.exist.xquery.parser.XQueryParser;
29+
import org.exist.xquery.parser.XQueryTokenTypes;
30+
import org.exist.xquery.parser.XQueryTreeParser;
31+
import org.junit.jupiter.api.Test;
32+
33+
import java.io.StringReader;
34+
35+
import static org.junit.Assert.*;
36+
37+
/**
38+
* @author <a href="[email protected]">Adam Retter</a>
39+
* @author <a href="[email protected]">Gabriele Tomassetti</a>
40+
*/
41+
public class ReservedNamesConflictTest {
42+
43+
@Test
44+
public void reservedNamesIssueTest() throws RecognitionException, XPathException, TokenStreamException {
45+
final String query = "xquery version \"3.1\";\n" +
46+
"<foo copy-namespaces=\"bar\"/>,\n" +
47+
"<foo empty-sequence=\"bar\"/>,\n" +
48+
"<foo schema-element=\"bar\"/>";
49+
50+
// parse the query into the internal syntax tree
51+
final XQueryContext context = new XQueryContext();
52+
final XQueryLexer lexer = new XQueryLexer(context, new StringReader(query));
53+
final XQueryParser xparser = new XQueryParser(lexer);
54+
xparser.xpath();
55+
if (xparser.foundErrors()) {
56+
fail(xparser.getErrorMessage());
57+
return;
58+
}
59+
60+
final XQueryAST ast = (XQueryAST) xparser.getAST();
61+
62+
final XQueryTreeParser treeParser = new XQueryTreeParser(context);
63+
final PathExpr expr = new PathExpr(context);
64+
treeParser.xpath(ast, expr);
65+
if (treeParser.foundErrors()) {
66+
fail(treeParser.getErrorMessage());
67+
return;
68+
}
69+
70+
71+
final XQueryAST one = (XQueryAST) ast.getNextSibling().getFirstChild().getFirstChild();
72+
final XQueryAST two = (XQueryAST) ast.getNextSibling().getFirstChild().getNextSibling().getFirstChild();
73+
final XQueryAST three = (XQueryAST) ast.getNextSibling().getFirstChild().getNextSibling().getNextSibling().getFirstChild();
74+
75+
assertEquals("copy-namespaces", one.getText());
76+
assertEquals("empty-sequence", two.getText());
77+
assertEquals("schema-element", three.getText());
78+
assertEquals(XQueryTokenTypes.ATTRIBUTE, one.getType());
79+
assertEquals(XQueryTokenTypes.ATTRIBUTE, two.getType());
80+
assertEquals(XQueryTokenTypes.ATTRIBUTE, three.getType());
81+
}
82+
}
83+

0 commit comments

Comments
 (0)