Fix character column number of XML parse error on line with closing tag of element with namespace preceding it

Frederic Vancraeyveldt <[email protected]> Mon, 15 Jun 2020 17:29:32 +0200
Newsgroups gmane.comp.gnome.lib.xml.general
Organization Secure IT vof
Message-ID <[email protected]>
Hi, 

I am using libxml2 in my application. 

I think xmlTextReaderGetParserColumnNumber returns the wrong column
number in certain cases. 

I traced the code and I have a suggested fix in libxml_parser.patch. 

I have attached an XML file which shows the error
(i_Dialogs_it.sdlxliff). 

I also modified xmllint a little bit to be able to show the error using
that tool. 

That modification is in patch (libxml_error.patch) 

Executing 

      xmllint i_Dialogs_it.sdlxliff 

should return
      file:i_Dialogs_it.sdlxliff:3:18: parser error : PCDATA invalid
Char value 4 ...
IMO 

but the original code returns column 13. 

Can you verify the fix and integrate it if you agree. 

I just joined this mailing list. Please advise me if there is a better
way of reporting these issues. 

Regards, 

Frederic

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
https://mail.gnome.org/mailman/listinfo/xml
libxml_error.patch (text/x-diff, 1.4 KB)
c:\utils\git\bin\git.exe diff error.c       
diff --git a/error.c b/error.c
index 3e41e173..ae3b38ff 100644
--- a/error.c
+++ b/error.c
@@ -247,6 +247,7 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
 {
     char *file = NULL;
     int line = 0;
+    int col = 0;
     int code = -1;
     int domain;
     const xmlChar *name = NULL;
@@ -264,6 +265,7 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
     }
     file = err->file;
     line = err->line;
+    col = err->int2;
     code = err->code;
     domain = err->domain;
     level = err->level;
@@ -287,13 +289,13 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
         }
         if (input != NULL) {
             if (input->filename)
-                channel(data, "%s:%d: ", input->filename, input->line);
+                channel(data, "%s:%d:%d: ", input->filename, input->line, input->col);
             else if ((line != 0) && (domain == XML_FROM_PARSER))
                 channel(data, "Entity: line %d: ", input->line);
         }
     } else {
         if (file != NULL)
-            channel(data, "%s:%d: ", file, line);
+            channel(data, "%s:%d:%d: ", file, line,col);
         else if ((line != 0) &&
 	         ((domain == XML_FROM_PARSER) || (domain == XML_FROM_SCHEMASV)||
 		  (domain == XML_FROM_SCHEMASP)||(domain == XML_FROM_DTD) ||
libxml_parser.patch (text/x-diff, 718 B)
c:\utils\git\bin\git.exe diff parser.c       
diff --git a/parser.c b/parser.c
index 3559aaae..ee961910 100644
--- a/parser.c
+++ b/parser.c
@@ -8806,6 +8806,7 @@ xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *name,
     const xmlChar *in;
     const xmlChar *ret;
     const xmlChar *prefix2;
+    int count;
 
     if (prefix == NULL) return(xmlParseNameAndCompare(ctxt, name));
 
@@ -8826,7 +8827,9 @@ xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *name,
 	}
 	if (*cmp == 0 && (*in == '>' || IS_BLANK_CH (*in))) {
 	    /* success */
+	    count = (in - ctxt->input->cur);			
 	    ctxt->input->cur = in;
+	    ctxt->input->col += count;
 	    return((const xmlChar*) 1);
 	}
     }
i_Dialogs_it.sdlxliff (application/xml, 138 B) - not displayed