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

Commit8db43db

Browse files
committed
Allow XML processing instructions starting with "xml" while prohibiting
those being exactly "xml". Bug #3735 from Ben Leslie
1 parent3991c3f commit8db43db

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

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

Lines changed: 16 additions & 3 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.53 2007/11/08 15:16:45 petere Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.54 2007/11/09 15:52:51 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -676,11 +676,11 @@ xmlpi(char *target, text *arg, bool arg_is_null, bool *result_is_null)
676676
xmltype*result;
677677
StringInfoDatabuf;
678678

679-
if (pg_strncasecmp(target,"xml",3)==0)
679+
if (pg_strcasecmp(target,"xml")==0)
680680
ereport(ERROR,
681681
(errcode(ERRCODE_SYNTAX_ERROR),/* really */
682682
errmsg("invalid XML processing instruction"),
683-
errdetail("XML processing instruction target name cannotstart with \"xml\".")));
683+
errdetail("XML processing instruction target name cannotbe \"%s\".",target)));
684684

685685
/*
686686
* Following the SQL standard, the null check comes after the
@@ -997,13 +997,22 @@ xml_init(void)
997997
#defineSKIP_XML_SPACE(p) \
998998
while (xmlIsBlank_ch(*(p))) (p)++
999999

1000+
/* Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender */
1001+
#definepg_xmlIsNameChar(c) \
1002+
(xmlIsBaseChar_ch(c) || xmlIsIdeographicQ(c) \
1003+
|| xmlIsDigit_ch(c) \
1004+
|| c == '.' || c == '-' || c == '_' || c == ':' \
1005+
|| xmlIsCombiningQ(c) \
1006+
|| xmlIsExtender_ch(c))
1007+
10001008
staticint
10011009
parse_xml_decl(constxmlChar*str,size_t*lenp,
10021010
xmlChar**version,xmlChar**encoding,int*standalone)
10031011
{
10041012
constxmlChar*p;
10051013
constxmlChar*save_p;
10061014
size_tlen;
1015+
intutf8len;
10071016

10081017
xml_init();
10091018

@@ -1019,6 +1028,10 @@ parse_xml_decl(const xmlChar *str,size_t *lenp,
10191028
if (xmlStrncmp(p, (xmlChar*)"<?xml",5)!=0)
10201029
gotofinished;
10211030

1031+
/* This means it's a PI like <?xml-stylesheet ...?>. */
1032+
if (pg_xmlIsNameChar(xmlGetUTF8Char(&p[5],&utf8len)))
1033+
gotofinished;
1034+
10221035
p+=5;
10231036

10241037
/* version */

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,15 @@ SELECT xmlpi(name foo);
180180
<?foo?>
181181
(1 row)
182182

183-
SELECT xmlpi(namexmlstuff);
183+
SELECT xmlpi(namexml);
184184
ERROR: invalid XML processing instruction
185-
DETAIL: XML processing instruction target name cannot start with "xml".
185+
DETAIL: XML processing instruction target name cannot be "xml".
186+
SELECT xmlpi(name xmlstuff);
187+
xmlpi
188+
--------------
189+
<?xmlstuff?>
190+
(1 row)
191+
186192
SELECT xmlpi(name foo, 'bar');
187193
xmlpi
188194
-------------
@@ -198,9 +204,21 @@ SELECT xmlpi(name foo, null);
198204

199205
(1 row)
200206

201-
SELECT xmlpi(namexmlstuff, null);
207+
SELECT xmlpi(namexml, null);
202208
ERROR: invalid XML processing instruction
203-
DETAIL: XML processing instruction target name cannot start with "xml".
209+
DETAIL: XML processing instruction target name cannot be "xml".
210+
SELECT xmlpi(name xmlstuff, null);
211+
xmlpi
212+
-------
213+
214+
(1 row)
215+
216+
SELECT xmlpi(name "xml-stylesheet", 'href="mystyle.css" type="text/css"');
217+
xmlpi
218+
-------------------------------------------------------
219+
<?xml-stylesheet href="mystyle.css" type="text/css"?>
220+
(1 row)
221+
204222
SELECT xmlpi(name foo, ' bar');
205223
xmlpi
206224
-------------

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ SELECT xmlpi(name foo);
140140
ERROR: unsupported XML feature
141141
DETAIL: This functionality requires the server to be built with libxml support.
142142
HINT: You need to rebuild PostgreSQL using --with-libxml.
143+
SELECT xmlpi(name xml);
144+
ERROR: unsupported XML feature
145+
DETAIL: This functionality requires the server to be built with libxml support.
146+
HINT: You need to rebuild PostgreSQL using --with-libxml.
143147
SELECT xmlpi(name xmlstuff);
144148
ERROR: unsupported XML feature
145149
DETAIL: This functionality requires the server to be built with libxml support.
@@ -156,10 +160,18 @@ SELECT xmlpi(name foo, null);
156160
ERROR: unsupported XML feature
157161
DETAIL: This functionality requires the server to be built with libxml support.
158162
HINT: You need to rebuild PostgreSQL using --with-libxml.
163+
SELECT xmlpi(name xml, null);
164+
ERROR: unsupported XML feature
165+
DETAIL: This functionality requires the server to be built with libxml support.
166+
HINT: You need to rebuild PostgreSQL using --with-libxml.
159167
SELECT xmlpi(name xmlstuff, null);
160168
ERROR: unsupported XML feature
161169
DETAIL: This functionality requires the server to be built with libxml support.
162170
HINT: You need to rebuild PostgreSQL using --with-libxml.
171+
SELECT xmlpi(name "xml-stylesheet", 'href="mystyle.css" type="text/css"');
172+
ERROR: unsupported XML feature
173+
DETAIL: This functionality requires the server to be built with libxml support.
174+
HINT: You need to rebuild PostgreSQL using --with-libxml.
163175
SELECT xmlpi(name foo, ' bar');
164176
ERROR: unsupported XML feature
165177
DETAIL: This functionality requires the server to be built with libxml support.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ SELECT xmlparse(document '<abc>x</abc>');
6161

6262

6363
SELECT xmlpi(name foo);
64+
SELECT xmlpi(name xml);
6465
SELECT xmlpi(name xmlstuff);
6566
SELECT xmlpi(name foo,'bar');
6667
SELECT xmlpi(name foo,'in?>valid');
6768
SELECT xmlpi(name foo,null);
69+
SELECT xmlpi(name xml,null);
6870
SELECT xmlpi(name xmlstuff,null);
71+
SELECT xmlpi(name"xml-stylesheet",'href="mystyle.css" type="text/css"');
6972
SELECT xmlpi(name foo,' bar');
7073

7174

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp