[PATCH] Bug in XPATH() if expression returns a scalar value - Mailing list pgsql-hackers

From Florian Pflug
Subject [PATCH] Bug in XPATH() if expression returns a scalar value
Date
Msg-id 33B182D9-D2C3-4BDF-A8C9-B896BC9B8629@phlo.org
Whole thread Raw
Responses Re: [PATCH] Bug in XPATH() if expression returns a scalar value  (Florian Pflug <fgp@phlo.org>)
List pgsql-hackers
Hi

The in-core XPATH() function currently only handles XPath expressions which
return a node set correctly. For XPath expressions which return boolean,
numeric or string values, XPATH() returns an empty array. (This is the case
for XPath expressions whose top-level syntactic construct isn't a path
expression but rather one of the built-in functions like name() or count()).

The XPath expression 'name(/*)', for example, is supposed to return 'root'
when applied to the XML fragment '<root><nested/><nested/></root>'. Postgres,
however, currently returns an empty array.

A patch which fixes that is attached. It makes XPATH() return a single-element
array containing a textual representation of the string, numeric value or boolean
for XPath expressions which don't return a node set. For numeric and boolean
results, the textual representation is obtained by calling float8out() respectively
boolout(). These function's results are assumed to always be well-form XML. For
string results, xml_in() is used to verify that the string returned by the XPath
expression is a well-formed XML fragment. This is required because XPATH() could
otherwise be used to insert invalid XML fragments into columns of type XML.

The patch add a few tests of non-nodeset returning XPath expressions to the
XML regression tests.

I'm not 100% clear on whether I should add this to the next commit fest or not -
after all, it's more a bug-fix rather than a new feature. But to prevent this
from getting lost, I'll add it unless someone tells me not to.

best regards,
Florian Pflug

Attachment

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Getting a bug tracker for the Postgres project
Next
From: Greg Smith
Date:
Subject: Re: How can I check the treatment of bug fixes?