[libxml2] wrong error column in structured error when parsing attribute values



commit 33f658c969501bb246f8d4c6d21772948c7bc965
Author: Juergen Keil <jrgn keil googlemail com>
Date:   Thu Aug 7 17:30:36 2014 +0800

    wrong error column in structured error when parsing attribute values
    
    For https://bugzilla.gnome.org/show_bug.cgi?id=734280
    
    libxml2 reports wrong error column numbers (field int2 in xmlError)
    in structured error handler, after parsing XML attribute values.
    
    Example XML:
    
    <?xml version="1.0" encoding="UTF-8"?>
    <root
    xmlns="urn:colbug">&</root>
    <!--
             1         2         3         4
    1234567890123456789012345678901234567890
    -->
    
    Expected location of the error would be line 3, column 21.
    
    The actual location of the error is line 3, column 9:
    
    $ ./xmlparse colbug2.xml
    colbug2.xml:3:9: xmlParseEntityRef: no name
    
    The 12 characters of the xmlns attribute value "urn:colbug" are
    not accounted for in the error column value.

 parser.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/parser.c b/parser.c
index fdb4514..39d391b 100644
--- a/parser.c
+++ b/parser.c
@@ -8932,9 +8932,12 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
     xmlChar limit = 0;
     const xmlChar *in = NULL, *start, *end, *last;
     xmlChar *ret = NULL;
+    int line, col;
 
     GROW;
     in = (xmlChar *) CUR_PTR;
+    line = ctxt->input->line;
+    col = ctxt->input->col;
     if (*in != '"' && *in != '\'') {
         xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL);
         return (NULL);
@@ -8947,6 +8950,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
      * pure ASCII.
      */
     limit = *in++;
+    col++;
     end = ctxt->input->end;
     start = in;
     if (in >= end) {
@@ -8966,6 +8970,11 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        while ((in < end) && (*in != limit) &&
               ((*in == 0x20) || (*in == 0x9) ||
                (*in == 0xA) || (*in == 0xD))) {
+           if (*in == 0xA) {
+               line++; col = 1;
+           } else {
+               col++;
+           }
            in++;
            start = in;
            if (in >= end) {
@@ -8989,6 +8998,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        }
        while ((in < end) && (*in != limit) && (*in >= 0x20) &&
               (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
+           col++;
            if ((*in++ == 0x20) && (*in == 0x20)) break;
            if (in >= end) {
                const xmlChar *oldbase = ctxt->input->base;
@@ -9017,6 +9027,11 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        while ((in < end) && (*in != limit) &&
               ((*in == 0x20) || (*in == 0x9) ||
                (*in == 0xA) || (*in == 0xD))) {
+           if (*in == 0xA) {
+               line++, col = 1;
+           } else {
+               col++;
+           }
            in++;
            if (in >= end) {
                const xmlChar *oldbase = ctxt->input->base;
@@ -9049,6 +9064,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        while ((in < end) && (*in != limit) && (*in >= 0x20) &&
               (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
            in++;
+           col++;
            if (in >= end) {
                const xmlChar *oldbase = ctxt->input->base;
                GROW;
@@ -9078,6 +9094,7 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        if (*in != limit) goto need_complex;
     }
     in++;
+    col++;
     if (len != NULL) {
         *len = last - start;
         ret = (xmlChar *) start;
@@ -9086,6 +9103,8 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
         ret = xmlStrndup(start, last - start);
     }
     CUR_PTR = in;
+    ctxt->input->line = line;
+    ctxt->input->col = col;
     if (alloc) *alloc = 0;
     return ret;
 need_complex:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]