After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 655156 - document('') fails to return stylesheets parsed from memory
document('') fails to return stylesheets parsed from memory
Status: RESOLVED FIXED
Product: libxslt
Classification: Platform
Component: general
1.1.26
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2011-07-23 00:03 UTC by Jason Viers
Modified: 2012-08-16 13:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Program demonstrating the issue (1.19 KB, text/plain)
2011-07-23 00:03 UTC, Jason Viers
  Details
Patch for function.c (1.76 KB, patch)
2011-07-23 00:14 UTC, Jason Viers
none Details | Review

Description Jason Viers 2011-07-23 00:03:38 UTC
Created attachment 192512 [details]
Program demonstrating the issue

If an XSL stylesheet is from memory (e.g. xmlParseMemory), then xpath expressions referencing "document('')" will never return a match.

Attached is a program that shows the problem using the libxslt/tests/general/array.xsl testcase.  It's read via xsltParseStylesheetFile and applied (successfully) and then read again via xmlParseMemory/xsltParseStylesheetDoc, and the two document('') expressions fail to match.
Comment 1 Jason Viers 2011-07-23 00:14:23 UTC
Created attachment 192515 [details] [review]
Patch for function.c

This was originally addressed in 2001:
http://mail.gnome.org/archives/xslt/2001-July/msg00112.html
style->doc->URL is NULL when XSL is read from memory, and the change allowed it to match a NULL URI.

That change in xsltDocumentFunctionLoadDocument was no longer being hit.  xsltDocumentFunction doesn't call the former if URI=NULL, and the former has a check to make sure URI isn't NULL.

This patch has xsltDocumentFunction check for style->doc->URL=NULL before bailing due to NULL URI.  Figured this was easier/cleaner than trying to propagate NULL URI down through Load again.
Comment 2 Jason Viers 2011-07-23 01:02:52 UTC
Just found that this was discussed in 2002, and the exact behavior implemented in the patch was deemed "not a good idea" by Daniel Veillard. :)
http://mail.gnome.org/archives/xslt/2002-July/msg00030.html
http://mail.gnome.org/archives/xslt/2002-June/msg00060.html

It was recommended to instead use xmlNodeSetBase() to give the doc a non-NULL base.

When getting down into it, I understand the logic "document() is resolved relative to the XSL's location, reading from memory has no location, therefore buzz off", but the XSL spec seems to address this:

http://www.w3.org/TR/xslt#document
"Note that a zero-length URI reference is a reference to the document relative to which the URI reference is being resolved; thus document("") refers to the root node of the stylesheet; the tree representation of the stylesheet is exactly the same as if the XML document containing the stylesheet was the initial source document."


The fact that the behavior differs in this case between fromFile & fromMemory definitely caught me off guard, and IMHO fixing that scenario is worth the one-off-ness of the fix.
Comment 3 Daniel Veillard 2012-08-16 13:25:55 UTC
Okay, based on the spec comment, I agreed, though I still think
it's kind of an abuse :)

Applied:
http://git.gnome.org/browse/libxslt/commit/?id=5e184e7154e8aa466e988f17c8b97b65196f94bf
  

  thanks a lot :-)

Daniel