Skip to content

Commit 93f9b4a

Browse files
committed
xml2: Add tests for functions xpath_nodeset() and xpath_list()
These two functions with their different argument lists have never been tested in this module, so let's add something. Author: Ronan Dunklau Discussion: https://postgr.es/m/ZzMSJkiNZhimjXWx@paquier.xyz
1 parent 3ef038f commit 93f9b4a

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

contrib/xml2/expected/xml2.out

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,45 @@ SELECT xslt_process('<employee><name>cim</name><age>30</age><pay>400</pay></empl
207207

208208
(1 row)
209209

210+
-- xpath_nodeset()
211+
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages')
212+
FROM articles;
213+
xpath_nodeset
214+
----------------------------------------
215+
<author>test</author><pages>37</pages>
216+
(1 row)
217+
218+
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
219+
'item_without_toptag')
220+
FROM articles;
221+
xpath_nodeset
222+
------------------------------------------------------------------------------------------------------------------------------
223+
<item_without_toptag><author>test</author></item_without_toptag><item_without_toptag><pages>37</pages></item_without_toptag>
224+
(1 row)
225+
226+
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
227+
'result', 'item')
228+
FROM articles;
229+
xpath_nodeset
230+
-----------------------------------------------------------------------------------
231+
<result><item><author>test</author></item><item><pages>37</pages></item></result>
232+
(1 row)
233+
234+
-- xpath_list()
235+
SELECT xpath_list(article_xml::text, '/article/author|/article/pages')
236+
FROM articles;
237+
xpath_list
238+
------------
239+
test,37
240+
(1 row)
241+
242+
SELECT xpath_list(article_xml::text, '/article/author|/article/pages', '|')
243+
FROM articles;
244+
xpath_list
245+
------------
246+
test|37
247+
(1 row)
248+
210249
-- possible security exploit
211250
SELECT xslt_process('<xml><foo>Hello from XML</foo></xml>',
212251
$$<xsl:stylesheet version="1.0"

contrib/xml2/expected/xml2_1.out

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,45 @@ SELECT xslt_process('<employee><name>cim</name><age>30</age><pay>400</pay></empl
151151
</xsl:template>
152152
</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);
153153
ERROR: xslt_process() is not available without libxslt
154+
-- xpath_nodeset()
155+
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages')
156+
FROM articles;
157+
xpath_nodeset
158+
----------------------------------------
159+
<author>test</author><pages>37</pages>
160+
(1 row)
161+
162+
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
163+
'item_without_toptag')
164+
FROM articles;
165+
xpath_nodeset
166+
------------------------------------------------------------------------------------------------------------------------------
167+
<item_without_toptag><author>test</author></item_without_toptag><item_without_toptag><pages>37</pages></item_without_toptag>
168+
(1 row)
169+
170+
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
171+
'result', 'item')
172+
FROM articles;
173+
xpath_nodeset
174+
-----------------------------------------------------------------------------------
175+
<result><item><author>test</author></item><item><pages>37</pages></item></result>
176+
(1 row)
177+
178+
-- xpath_list()
179+
SELECT xpath_list(article_xml::text, '/article/author|/article/pages')
180+
FROM articles;
181+
xpath_list
182+
------------
183+
test,37
184+
(1 row)
185+
186+
SELECT xpath_list(article_xml::text, '/article/author|/article/pages', '|')
187+
FROM articles;
188+
xpath_list
189+
------------
190+
test|37
191+
(1 row)
192+
154193
-- possible security exploit
155194
SELECT xslt_process('<xml><foo>Hello from XML</foo></xml>',
156195
$$<xsl:stylesheet version="1.0"

contrib/xml2/sql/xml2.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ SELECT xslt_process('<employee><name>cim</name><age>30</age><pay>400</pay></empl
123123
</xsl:template>
124124
</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);
125125

126+
-- xpath_nodeset()
127+
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages')
128+
FROM articles;
129+
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
130+
'item_without_toptag')
131+
FROM articles;
132+
SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
133+
'result', 'item')
134+
FROM articles;
135+
136+
-- xpath_list()
137+
SELECT xpath_list(article_xml::text, '/article/author|/article/pages')
138+
FROM articles;
139+
SELECT xpath_list(article_xml::text, '/article/author|/article/pages', '|')
140+
FROM articles;
141+
126142
-- possible security exploit
127143
SELECT xslt_process('<xml><foo>Hello from XML</foo></xml>',
128144
$$<xsl:stylesheet version="1.0"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy