public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* xmlstarlet ignores XML attributes
@ 2017-09-30 17:07 Kay Ulbrich
  2017-10-02 19:10 ` libxml2: Attribute decoding patch (was: Re: xmlstarlet ignores XML attributes) David Stacey
  0 siblings, 1 reply; 2+ messages in thread
From: Kay Ulbrich @ 2017-09-30 17:07 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2025 bytes --]

Hello,

on a current Cygwin-installation, xmlstarlet fails to validate a valid
XML document against an XML schema (XSD). One gets error messages like

attribute 'date': '' is not a valid value of the atomic type 'xs:dateTime'.

on attributes, which are present. The behaviour can be reproduced using
the example files from the attached tar-archive via:

	xmlstarlet val -e -s minimal.xsd minimal.xml

On the versions installed on Debian Testing, for instance, the
validation works for the same documents.

I found a quite recent similar bug report for Debian, there seems to be
a problem with certain versions of libxml:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=832602

Additional information below.

*Failing on Cygwin:*

$ uname -a
CYGWIN_NT-10.0 goe-nb-ubk-w10 2.9.0(0.318/5/3) 2017-09-12 10:18 x86_64
Cygwin

$ xmlstarlet --version
1.6.1
compiled against libxml2 2.9.1, linked with 20904
compiled against libxslt 1.1.28, linked with 10129

$ ldd `which xmlstarlet.exe`
        ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x7ffbcc5e0000)
        KERNEL32.DLL => /cygdrive/c/Windows/System32/KERNEL32.DLL
(0x7ffbca5f0000)
        KERNELBASE.dll => /cygdrive/c/Windows/System32/KERNELBASE.dll
(0x7ffbc94a0000)
        cygwin1.dll => /usr/bin/cygwin1.dll (0x180040000)
        cygexslt-0.dll => /usr/bin/cygexslt-0.dll (0x3f35d0000)
        cygxml2-2.dll => /usr/bin/cygxml2-2.dll (0x3f3cf0000)
        cygxslt-1.dll => /usr/bin/cygxslt-1.dll (0x3e1240000)
        cyggcrypt-20.dll => /usr/bin/cyggcrypt-20.dll (0x3ee1b0000)
        cygiconv-2.dll => /usr/bin/cygiconv-2.dll (0x3fa9c0000)
        cyglzma-5.dll => /usr/bin/cyglzma-5.dll (0x3f5af0000)
        cygz.dll => /usr/bin/cygz.dll (0x3f3c90000)
        cyggpg-error-0.dll => /usr/bin/cyggpg-error-0.dll (0x3eda70000)
        cygintl-8.dll => /usr/bin/cygintl-8.dll (0x3fa890000)

*Here it worked (Debian Testing):*

$ xmlstarlet --version
1.6.1
compiled against libxml2 2.9.4, linked with 20904
compiled against libxslt 1.1.29, linked with 10129




[-- Attachment #2: libxmlbug.txz --]
[-- Type: application/octet-stream, Size: 680 bytes --]

[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

* libxml2: Attribute decoding patch (was: Re: xmlstarlet ignores XML attributes)
  2017-09-30 17:07 xmlstarlet ignores XML attributes Kay Ulbrich
@ 2017-10-02 19:10 ` David Stacey
  0 siblings, 0 replies; 2+ messages in thread
From: David Stacey @ 2017-10-02 19:10 UTC (permalink / raw)
  To: cygwin; +Cc: kay_ulbrich

[-- Attachment #1: Type: text/plain, Size: 647 bytes --]

On 30/09/2017 16:25, Kay Ulbrich wrote:
> on a current Cygwin-installation, xmlstarlet fails to validate a valid
> XML document against an XML schema (XSD).
>
> [snip]
>
> I found a quite recent similar bug report for Debian, there seems to be
> a problem with certain versions of libxml:
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=832602

Yaakov, please could you consider taking the patch attached, which is 
from Debian Stretch [1]. Or you may prefer to update to libxml2-2.9.5, 
as the patch has been incorporated upstream. Either should address the 
problem reported above.

Dave.

[1] - https://packages.debian.org/stretch/libxml2


[-- Attachment #2: 0008-Fix-attribute-decoding-during-XML-schema-validation.patch --]
[-- Type: text/plain, Size: 2311 bytes --]

From 256366ed60f8795279b25f7b7b55e8089b4c6ff4 Mon Sep 17 00:00:00 2001
From: Alex Henrie <alexhenrie24@gmail.com>
Date: Thu, 26 May 2016 17:38:35 -0600
Subject: [PATCH] Fix attribute decoding during XML schema validation

For https://bugzilla.gnome.org/show_bug.cgi?id=766834

vctxt->parserCtxt is always NULL in xmlSchemaSAXHandleStartElementNs,
so this function can't call xmlStringLenDecodeEntities to decode the
entities.
---
 xmlschemas.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/xmlschemas.c b/xmlschemas.c
index e1b3a4f..59535e5 100644
--- a/xmlschemas.c
+++ b/xmlschemas.c
@@ -27391,6 +27391,7 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
     * attributes yet.
     */
     if (nb_attributes != 0) {
+	int valueLen, k, l;
 	xmlChar *value;
 
         for (j = 0, i = 0; i < nb_attributes; i++, j += 5) {
@@ -27400,12 +27401,31 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
 	    * libxml2 differs from normal SAX here in that it escapes all ampersands
 	    * as &#38; instead of delivering the raw converted string. Changing the
 	    * behavior at this point would break applications that use this API, so
-	    * we are forced to work around it. There is no danger of accidentally
-	    * decoding some entity other than &#38; in this step because without
-	    * unescaped ampersands there can be no other entities in the string.
+	    * we are forced to work around it.
 	    */
-	    value = xmlStringLenDecodeEntities(vctxt->parserCtxt, attributes[j+3],
-		attributes[j+4] - attributes[j+3], XML_SUBSTITUTE_REF, 0, 0, 0);
+	    valueLen = attributes[j+4] - attributes[j+3];
+	    value = xmlMallocAtomic(valueLen + 1);
+	    if (value == NULL) {
+		xmlSchemaVErrMemory(vctxt,
+		    "allocating string for decoded attribute",
+		    NULL);
+		goto internal_error;
+	    }
+	    for (k = 0, l = 0; k < valueLen; l++) {
+		if (k < valueLen - 4 &&
+		    attributes[j+3][k+0] == '&' &&
+		    attributes[j+3][k+1] == '#' &&
+		    attributes[j+3][k+2] == '3' &&
+		    attributes[j+3][k+3] == '8' &&
+		    attributes[j+3][k+4] == ';') {
+		    value[l] = '&';
+		    k += 5;
+		} else {
+		    value[l] = attributes[j+3][k];
+		    k++;
+		}
+	    }
+	    value[l] = '\0';
 	    /*
 	    * TODO: Set the node line.
 	    */
-- 
2.8.3


[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-02 19:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-30 17:07 xmlstarlet ignores XML attributes Kay Ulbrich
2017-10-02 19:10 ` libxml2: Attribute decoding patch (was: Re: xmlstarlet ignores XML attributes) David Stacey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).