Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a32ba2

Browse files
committed
Prevent duplicate attribute names in XMLELEMENT.
1 parent19f9376 commit3a32ba2

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

‎src/backend/parser/parse_expr.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.204 2007/01/05 22:19:34 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.205 2007/01/08 23:41:56 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1415,15 +1415,31 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x)
14151415
ereport(ERROR,
14161416
(errcode(ERRCODE_SYNTAX_ERROR),
14171417
x->op==IS_XMLELEMENT
1418-
?errmsg("unnamed attribute value must be a column reference")
1419-
:errmsg("unnamed element value must be a column reference")));
1418+
?errmsg("unnamedXMLattribute value must be a column reference")
1419+
:errmsg("unnamedXMLelement value must be a column reference")));
14201420
argname=NULL;/* keep compiler quiet */
14211421
}
14221422

14231423
newx->named_args=lappend(newx->named_args,expr);
14241424
newx->arg_names=lappend(newx->arg_names,makeString(argname));
14251425
}
14261426

1427+
if (x->op==IS_XMLELEMENT)
1428+
{
1429+
foreach(lc,newx->arg_names)
1430+
{
1431+
ListCell*lc2;
1432+
1433+
for_each_cell(lc2,lnext(lc))
1434+
{
1435+
if (strcmp(strVal(lfirst(lc)),strVal(lfirst(lc2)))==0)
1436+
ereport(ERROR,
1437+
(errcode(ERRCODE_SYNTAX_ERROR),
1438+
errmsg("XML attribute name \"%s\" appears more than once",strVal(lfirst(lc)))));
1439+
}
1440+
}
1441+
}
1442+
14271443
/* The other arguments are of varying types depending on the function */
14281444
newx->args=NIL;
14291445
i=0;

‎src/test/regress/expected/xml.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ SELECT xmlelement(name element,
6565

6666
SELECT xmlelement(name element,
6767
xmlattributes ('unnamed and wrong'));
68-
ERROR: unnamed attribute value must be a column reference
68+
ERROR: unnamedXMLattribute value must be a column reference
6969
SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
7070
xmlelement
7171
-------------------------------------------
@@ -85,6 +85,8 @@ SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
8585

8686
SELECT xmlelement(name wrong, 37);
8787
ERROR: argument of XMLELEMENT must be type xml, not type integer
88+
SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
89+
ERROR: XML attribute name "a" appears more than once
8890
SELECT xmlparse(content 'abc');
8991
xmlparse
9092
----------

‎src/test/regress/expected/xml_1.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
4646
ERROR: no XML support in this installation
4747
SELECT xmlelement(name wrong, 37);
4848
ERROR: no XML support in this installation
49+
SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
50+
ERROR: no XML support in this installation
4951
SELECT xmlparse(content 'abc');
5052
ERROR: no XML support in this installation
5153
SELECT xmlparse(content '<abc>x</abc>');

‎src/test/regress/sql/xml.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
3838
SELECT xmlelement(name employee, xmlforest(name, age, salaryas pay))FROM emp;
3939

4040
SELECT xmlelement(name wrong,37);
41+
SELECT xmlelement(name duplicate, xmlattributes(1as a,2as b,3as a));
4142

4243

4344
SELECT xmlparse(content'abc');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp