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

Commitc04fd1b

Browse files
committed
Remove the arbitrary (and undocumented) limit on the number of parameter=value
pairs that can be handled by xslt_process().There is much else to do here, but this patch seems useful in its own rightfor as long as this code survives.Pavel Stehule, reviewed by Mike Fowler
1 parent33f4372 commitc04fd1b

File tree

4 files changed

+200
-19
lines changed

4 files changed

+200
-19
lines changed

‎contrib/xml2/expected/xml2.out

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,71 @@ values
145145
Value</attribute></attributes>');
146146
create index idx_xpath on t1 ( xpath_string
147147
('/attributes/attribute[@name="attr_1"]/text()', xml_data::text));
148+
SELECT xslt_process('<employee><name>cim</name><age>30</age><pay>400</pay></employee>'::text, $$<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
149+
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
150+
<xsl:strip-space elements="*"/>
151+
<xsl:param name="n1"/>
152+
<xsl:param name="n2"/>
153+
<xsl:param name="n3"/>
154+
<xsl:param name="n4"/>
155+
<xsl:param name="n5" select="'me'"/>
156+
<xsl:template match="*">
157+
<xsl:element name="samples">
158+
<xsl:element name="sample">
159+
<xsl:value-of select="$n1"/>
160+
</xsl:element>
161+
<xsl:element name="sample">
162+
<xsl:value-of select="$n2"/>
163+
</xsl:element>
164+
<xsl:element name="sample">
165+
<xsl:value-of select="$n3"/>
166+
</xsl:element>
167+
<xsl:element name="sample">
168+
<xsl:value-of select="$n4"/>
169+
</xsl:element>
170+
<xsl:element name="sample">
171+
<xsl:value-of select="$n5"/>
172+
</xsl:element>
173+
<xsl:element name="sample">
174+
<xsl:value-of select="$n6"/>
175+
</xsl:element>
176+
<xsl:element name="sample">
177+
<xsl:value-of select="$n7"/>
178+
</xsl:element>
179+
<xsl:element name="sample">
180+
<xsl:value-of select="$n8"/>
181+
</xsl:element>
182+
<xsl:element name="sample">
183+
<xsl:value-of select="$n9"/>
184+
</xsl:element>
185+
<xsl:element name="sample">
186+
<xsl:value-of select="$n10"/>
187+
</xsl:element>
188+
<xsl:element name="sample">
189+
<xsl:value-of select="$n11"/>
190+
</xsl:element>
191+
<xsl:element name="sample">
192+
<xsl:value-of select="$n12"/>
193+
</xsl:element>
194+
</xsl:element>
195+
</xsl:template>
196+
</xsl:stylesheet>$$::text, 'n1="v1",n2="v2",n3="v3",n4="v4",n5="v5",n6="v6",n7="v7",n8="v8",n9="v9",n10="v10",n11="v11",n12="v12"'::text);
197+
xslt_process
198+
------------------------
199+
<samples> +
200+
<sample>v1</sample> +
201+
<sample>v2</sample> +
202+
<sample>v3</sample> +
203+
<sample>v4</sample> +
204+
<sample>v5</sample> +
205+
<sample>v6</sample> +
206+
<sample>v7</sample> +
207+
<sample>v8</sample> +
208+
<sample>v9</sample> +
209+
<sample>v10</sample>+
210+
<sample>v11</sample>+
211+
<sample>v12</sample>+
212+
</samples> +
213+
214+
(1 row)
215+

‎contrib/xml2/expected/xml2_1.out

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,53 @@ values
107107
Value</attribute></attributes>');
108108
create index idx_xpath on t1 ( xpath_string
109109
('/attributes/attribute[@name="attr_1"]/text()', xml_data::text));
110+
SELECT xslt_process('<employee><name>cim</name><age>30</age><pay>400</pay></employee>'::text, $$<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
111+
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
112+
<xsl:strip-space elements="*"/>
113+
<xsl:param name="n1"/>
114+
<xsl:param name="n2"/>
115+
<xsl:param name="n3"/>
116+
<xsl:param name="n4"/>
117+
<xsl:param name="n5" select="'me'"/>
118+
<xsl:template match="*">
119+
<xsl:element name="samples">
120+
<xsl:element name="sample">
121+
<xsl:value-of select="$n1"/>
122+
</xsl:element>
123+
<xsl:element name="sample">
124+
<xsl:value-of select="$n2"/>
125+
</xsl:element>
126+
<xsl:element name="sample">
127+
<xsl:value-of select="$n3"/>
128+
</xsl:element>
129+
<xsl:element name="sample">
130+
<xsl:value-of select="$n4"/>
131+
</xsl:element>
132+
<xsl:element name="sample">
133+
<xsl:value-of select="$n5"/>
134+
</xsl:element>
135+
<xsl:element name="sample">
136+
<xsl:value-of select="$n6"/>
137+
</xsl:element>
138+
<xsl:element name="sample">
139+
<xsl:value-of select="$n7"/>
140+
</xsl:element>
141+
<xsl:element name="sample">
142+
<xsl:value-of select="$n8"/>
143+
</xsl:element>
144+
<xsl:element name="sample">
145+
<xsl:value-of select="$n9"/>
146+
</xsl:element>
147+
<xsl:element name="sample">
148+
<xsl:value-of select="$n10"/>
149+
</xsl:element>
150+
<xsl:element name="sample">
151+
<xsl:value-of select="$n11"/>
152+
</xsl:element>
153+
<xsl:element name="sample">
154+
<xsl:value-of select="$n12"/>
155+
</xsl:element>
156+
</xsl:element>
157+
</xsl:template>
158+
</xsl:stylesheet>$$::text, 'n1="v1",n2="v2",n3="v3",n4="v4",n5="v5",n6="v6",n7="v7",n8="v8",n9="v9",n10="v10",n11="v11",n12="v12"'::text);
159+
ERROR: xslt_process() is not available without libxslt

‎contrib/xml2/sql/xml2.sql

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,53 @@ Value</attribute></attributes>');
8080

8181
createindexidx_xpathon t1 ( xpath_string
8282
('/attributes/attribute[@name="attr_1"]/text()', xml_data::text));
83+
84+
SELECT xslt_process('<employee><name>cim</name><age>30</age><pay>400</pay></employee>'::text, $$<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
85+
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
86+
<xsl:strip-space elements="*"/>
87+
<xsl:param name="n1"/>
88+
<xsl:param name="n2"/>
89+
<xsl:param name="n3"/>
90+
<xsl:param name="n4"/>
91+
<xsl:param name="n5"select="'me'"/>
92+
<xsl:template match="*">
93+
<xsl:element name="samples">
94+
<xsl:element name="sample">
95+
<xsl:value-ofselect="$n1"/>
96+
</xsl:element>
97+
<xsl:element name="sample">
98+
<xsl:value-ofselect="$n2"/>
99+
</xsl:element>
100+
<xsl:element name="sample">
101+
<xsl:value-ofselect="$n3"/>
102+
</xsl:element>
103+
<xsl:element name="sample">
104+
<xsl:value-ofselect="$n4"/>
105+
</xsl:element>
106+
<xsl:element name="sample">
107+
<xsl:value-ofselect="$n5"/>
108+
</xsl:element>
109+
<xsl:element name="sample">
110+
<xsl:value-ofselect="$n6"/>
111+
</xsl:element>
112+
<xsl:element name="sample">
113+
<xsl:value-ofselect="$n7"/>
114+
</xsl:element>
115+
<xsl:element name="sample">
116+
<xsl:value-ofselect="$n8"/>
117+
</xsl:element>
118+
<xsl:element name="sample">
119+
<xsl:value-ofselect="$n9"/>
120+
</xsl:element>
121+
<xsl:element name="sample">
122+
<xsl:value-ofselect="$n10"/>
123+
</xsl:element>
124+
<xsl:element name="sample">
125+
<xsl:value-ofselect="$n11"/>
126+
</xsl:element>
127+
<xsl:element name="sample">
128+
<xsl:value-ofselect="$n12"/>
129+
</xsl:element>
130+
</xsl:element>
131+
</xsl:template>
132+
</xsl:stylesheet>$$::text,'n1="v1",n2="v2",n3="v3",n4="v4",n5="v5",n6="v6",n7="v7",n8="v8",n9="v9",n10="v10",n11="v11",n12="v12"'::text);

‎contrib/xml2/xslt_proc.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/xml2/xslt_proc.c,v 1.21 2010/07/06 19:18:55 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/xml2/xslt_proc.c,v 1.22 2010/08/10 23:02:00 tgl Exp $
33
*
44
* XSLT processing functions (requiring libxslt)
55
*
@@ -41,9 +41,8 @@ Datumxslt_process(PG_FUNCTION_ARGS);
4141
externvoidpgxml_parser_init(void);
4242

4343
/* local defs */
44-
staticvoidparse_params(constchar**params,text*paramstr);
44+
staticconstchar**parse_params(text*paramstr);
4545

46-
#defineMAXPARAMS 20/* must be even, see parse_params() */
4746
#endif/* USE_LIBXSLT */
4847

4948

@@ -57,7 +56,7 @@ xslt_process(PG_FUNCTION_ARGS)
5756
text*doct=PG_GETARG_TEXT_P(0);
5857
text*ssheet=PG_GETARG_TEXT_P(1);
5958
text*paramstr;
60-
constchar*params[MAXPARAMS+1];/* +1 for the terminator */
59+
constchar**params;
6160
xsltStylesheetPtrstylesheet=NULL;
6261
xmlDocPtrdoctree;
6362
xmlDocPtrrestree;
@@ -69,11 +68,14 @@ xslt_process(PG_FUNCTION_ARGS)
6968
if (fcinfo->nargs==3)
7069
{
7170
paramstr=PG_GETARG_TEXT_P(2);
72-
parse_params(params,paramstr);
71+
params=parse_params(paramstr);
7372
}
7473
else
74+
{
7575
/* No parameters */
76+
params= (constchar**)palloc(sizeof(char*));
7677
params[0]=NULL;
78+
}
7779

7880
/* Setup parser */
7981
pgxml_parser_init();
@@ -139,22 +141,34 @@ xslt_process(PG_FUNCTION_ARGS)
139141

140142
#ifdefUSE_LIBXSLT
141143

142-
staticvoid
143-
parse_params(constchar**params,text*paramstr)
144+
staticconstchar**
145+
parse_params(text*paramstr)
144146
{
145147
char*pos;
146148
char*pstr;
147-
inti;
148149
char*nvsep="=";
149150
char*itsep=",";
151+
constchar**params;
152+
intmax_params;
153+
intnparams;
150154

151155
pstr=text_to_cstring(paramstr);
152156

157+
max_params=20;/* must be even! */
158+
params= (constchar**)palloc((max_params+1)*sizeof(char*));
159+
nparams=0;
160+
153161
pos=pstr;
154162

155-
for (i=0;i<MAXPARAMS;i++)
163+
while (*pos!='\0')
156164
{
157-
params[i]=pos;
165+
if (nparams >=max_params)
166+
{
167+
max_params *=2;
168+
params= (constchar**)repalloc(params,
169+
(max_params+1)*sizeof(char*));
170+
}
171+
params[nparams++]=pos;
158172
pos=strstr(pos,nvsep);
159173
if (pos!=NULL)
160174
{
@@ -164,27 +178,26 @@ parse_params(const char **params, text *paramstr)
164178
else
165179
{
166180
/* No equal sign, so ignore this "parameter" */
167-
/* We'll reset params[i] to NULL below the loop */
181+
nparams--;
168182
break;
169183
}
170-
/* Value */
171-
i++;
172-
/* since MAXPARAMS is even, we still have i < MAXPARAMS */
173-
params[i]=pos;
184+
185+
/* since max_params is even, we still have nparams < max_params */
186+
params[nparams++]=pos;
174187
pos=strstr(pos,itsep);
175188
if (pos!=NULL)
176189
{
177190
*pos='\0';
178191
pos++;
179192
}
180193
else
181-
{
182-
i++;
183194
break;
184-
}
185195
}
186196

187-
params[i]=NULL;
197+
/* Add the terminator marker; we left room for it in the palloc's */
198+
params[nparams]=NULL;
199+
200+
returnparams;
188201
}
189202

190203
#endif/* USE_LIBXSLT */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp