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

Commitd807c7e

Browse files
committed
Some fine-tuning of xmlpi in corner cases:
- correct error codes- do syntax checks in correct order- strip leading spaces of argument
1 parentde9aa5a commitd807c7e

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

‎src/backend/executor/execQual.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.203 2007/01/05 22:19:27 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.204 2007/01/07 22:49:55 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2803,15 +2803,17 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
28032803
e= (ExprState*)linitial(xmlExpr->args);
28042804
value=ExecEvalExpr(e,econtext,&isnull,NULL);
28052805
if (isnull)
2806-
return (Datum)0;
2807-
arg=DatumGetTextP(value);
2806+
arg=NULL;
2807+
else
2808+
arg=DatumGetTextP(value);
28082809
}
28092810
else
2811+
{
28102812
arg=NULL;
2813+
isnull= false;
2814+
}
28112815

2812-
*isNull= false;
2813-
2814-
returnPointerGetDatum(xmlpi(xexpr->name,arg));
2816+
returnPointerGetDatum(xmlpi(xexpr->name,arg,isnull,isNull));
28152817
}
28162818
break;
28172819

‎src/backend/utils/adt/xml.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.12 2007/01/0700:13:55 petere Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.13 2007/01/0722:49:56 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -257,18 +257,26 @@ xmlparse(text *data, bool is_document, bool preserve_whitespace)
257257

258258

259259
xmltype*
260-
xmlpi(char*target,text*arg)
260+
xmlpi(char*target,text*arg,boolarg_is_null,bool*result_is_null)
261261
{
262262
#ifdefUSE_LIBXML
263263
xmltype*result;
264264
StringInfoDatabuf;
265265

266266
if (pg_strncasecmp(target,"xml",3)==0)
267267
ereport(ERROR,
268-
(errcode(ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION),
268+
(errcode(ERRCODE_SYNTAX_ERROR),/* really */
269269
errmsg("invalid XML processing instruction"),
270270
errdetail("XML processing instruction target name cannot start with \"xml\".")));
271271

272+
/*
273+
* Following the SQL standard, the null check comes after the
274+
* syntax check above.
275+
*/
276+
*result_is_null=arg_is_null;
277+
if (*result_is_null)
278+
returnNULL;
279+
272280
initStringInfo(&buf);
273281

274282
appendStringInfo(&buf,"<?%s",target);
@@ -286,7 +294,7 @@ xmlpi(char *target, text *arg)
286294
errdetail("XML processing instruction cannot contain \"?>\".")));
287295

288296
appendStringInfoChar(&buf,' ');
289-
appendStringInfoString(&buf,string);
297+
appendStringInfoString(&buf,string+strspn(string," "));
290298
pfree(string);
291299
}
292300
appendStringInfoString(&buf,"?>");

‎src/include/utils/xml.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/xml.h,v 1.6 2007/01/05 22:20:00 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/xml.h,v 1.7 2007/01/07 22:49:56 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -33,7 +33,7 @@ extern Datum texttoxml(PG_FUNCTION_ARGS);
3333
externDatumxmlvalidate(PG_FUNCTION_ARGS);
3434

3535
externxmltype*xmlparse(text*data,boolis_doc,boolpreserve_whitespace);
36-
externxmltype*xmlpi(char*target,text*arg);
36+
externxmltype*xmlpi(char*target,text*arg,boolarg_is_null,bool*result_is_null);
3737
externxmltype*xmlroot(xmltype*data,text*version,intstandalone);
3838

3939
externchar*map_sql_identifier_to_xml_name(char*ident,boolfully_escaped);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ SELECT xmlpi(name foo, 'bar');
124124
SELECT xmlpi(name foo, 'in?>valid');
125125
ERROR: invalid XML processing instruction
126126
DETAIL: XML processing instruction cannot contain "?>".
127+
SELECT xmlpi(name foo, null);
128+
xmlpi
129+
-------
130+
131+
(1 row)
132+
133+
SELECT xmlpi(name xmlstuff, null);
134+
ERROR: invalid XML processing instruction
135+
DETAIL: XML processing instruction target name cannot start with "xml".
136+
SELECT xmlpi(name foo, ' bar');
137+
xmlpi
138+
-------------
139+
<?foo bar?>
140+
(1 row)
141+
127142
SELECT xmlroot(xml '<foo/>', version no value, standalone no value);
128143
xmlroot
129144
-----------------------

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ SELECT xmlpi(name foo, 'bar');
6262
ERROR: no XML support in this installation
6363
SELECT xmlpi(name foo, 'in?>valid');
6464
ERROR: no XML support in this installation
65+
SELECT xmlpi(name foo, null);
66+
ERROR: no XML support in this installation
67+
SELECT xmlpi(name xmlstuff, null);
68+
ERROR: no XML support in this installation
69+
SELECT xmlpi(name foo, ' bar');
70+
ERROR: no XML support in this installation
6571
SELECT xmlroot(xml '<foo/>', version no value, standalone no value);
6672
ERROR: no XML support in this installation
6773
SELECT xmlroot(xml '<foo/>', version '2.0');

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ SELECT xmlpi(name foo);
5151
SELECT xmlpi(name xmlstuff);
5252
SELECT xmlpi(name foo,'bar');
5353
SELECT xmlpi(name foo,'in?>valid');
54+
SELECT xmlpi(name foo,null);
55+
SELECT xmlpi(name xmlstuff,null);
56+
SELECT xmlpi(name foo,' bar');
5457

5558
SELECT xmlroot(xml'<foo/>', version no value, standalone no value);
5659
SELECT xmlroot(xml'<foo/>', version'2.0');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp