Thread: BUG #3735: Can't create xml-stylesheet processing instruction

BUG #3735: Can't create xml-stylesheet processing instruction

From
"Ben Leslie"
Date:
The following bug has been logged online:

Bug reference:      3735
Logged by:          Ben Leslie
Email address:      benno@benno.id.au
PostgreSQL version: 8.3 beta 2
Operating system:   Mac OS X
Description:        Can't create xml-stylesheet processing instruction
Details:

# select xmlpi(name "xml-stylesheet");
ERROR:  invalid XML processing instruction
DETAIL:  XML processing instruction target name cannot start with "xml".

The w3c XML 1.0 spec says that PIs starting with 'xml' are reserved.

(http://www.w3.org/TR/REC-xml/#sec-pi)

However the w3c stylesheet recommendation
(http://www.w3.org/TR/xml-stylesheet/) specifies a xml-stylesheet processing
instruction, so it would be useful to be able to handle this.

Re: BUG #3735: Can't create xml-stylesheet processing instruction

From
Peter Eisentraut
Date:
Am Freitag, 9. November 2007 schrieb Ben Leslie:
> # select xmlpi(name "xml-stylesheet");
> ERROR:  invalid XML processing instruction
> DETAIL:  XML processing instruction target name cannot start with "xml".

Apparently I read the SQL spec a bit to strictly here.  I've installed a fix
into CVS.

> The w3c XML 1.0 spec says that PIs starting with 'xml' are reserved.

That's what I thought as well, but they actually only reserve names being
exactly 'xml' modulo case differences.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

Re: BUG #3735: Can't create xml-stylesheet processing instruction

From
Ben Leslie
Date:
On Fri Nov 09, 2007 at 16:53:08 +0100, Peter Eisentraut wrote:
>Am Freitag, 9. November 2007 schrieb Ben Leslie:
>> # select xmlpi(name "xml-stylesheet");
>> ERROR:  invalid XML processing instruction
>> DETAIL:  XML processing instruction target name cannot start with "xml".
>
>Apparently I read the SQL spec a bit to strictly here.  I've installed a fix
>into CVS.
>
>> The w3c XML 1.0 spec says that PIs starting with 'xml' are reserved.
>
>That's what I thought as well, but they actually only reserve names being
>exactly 'xml' modulo case differences.

Hi,

I've installed from CVS. It is closed, but now I've got another error.
As an example, here is some code that gives me the output I expected:

okdb=#  select xmlroot(xmlpi(name "xsl-stylesheet"), version '1.0');
      xmlroot
--------------------
 <?xsl-stylesheet?>
(1 row)


If I know try this with but using the correct name "xml-stylesheet", the
output returned is null.

okdb=#  select xmlroot(xmlpi(name "xml-stylesheet"), version '1.0');
 xmlroot
---------


The reason for the bug is the new part of code in parse_xml_decl().
Specifically, utf8len is not initialised causing the problem.

A incomplete fix is changing it to be something along the lines of:

/* This means it's a PI like <?xml-stylesheet ...?>. */
utf8len = 4; /* FIXME: How do we know how many characters it could be?*/
utf8char = xmlGetUTF8Char(&p[5], &utf8len);
if (utf8char == -1) {
  /* The libxml docs don't actually specify why you could have an error
     here. Reading the source indicates an error would only occur in the
     case that utf8len is not long enough */
  printf("Error.. not sure what to do in this case?");
}
if (pg_xmlIsNameChar(utf8char))
   goto finished;


Obviously, there are a lot of problems in the small number of lines of code,
in particular how to get the correct value for utf8len, and also what
to do in the error case.

Not ever having touched libxml or postgres code before I don't really know
the right patch.

Cheers,

Benno

(P.S: Please CC me, I'm not on the list.. yet).

Re: BUG #3735: Can't create xml-stylesheet processing instruction

From
Tom Lane
Date:
Ben Leslie <benno@benno.id.au> writes:
> The reason for the bug is the new part of code in parse_xml_decl().
> Specifically, utf8len is not initialised causing the problem.

Yeah --- this also explains the regression test failures seen on some
but not all buildfarm machines.  Will fix.

            regards, tom lane

Re: BUG #3735: Can't create xml-stylesheet processing instruction

From
Peter Eisentraut
Date:
Ben Leslie wrote:
> utf8len = 4; /* FIXME: How do we know how many characters it could
> be?*/ utf8char = xmlGetUTF8Char(&p[5], &utf8len);

Where do you get the information that the second parameter of
xmlGetUTF8Char is used on input?

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

Re: BUG #3735: Can't create xml-stylesheet processing instruction

From
Tom Lane
Date:
Peter Eisentraut <peter_e@gmx.net> writes:
> Where do you get the information that the second parameter of
> xmlGetUTF8Char is used on input?

From reading the manual, eg here:
http://xmlsoft.org/html/libxml-xmlstring.html#xmlGetUTF8Char

            regards, tom lane