Commits

Shlomi Fish  committed 784037d

$err->column() no longer maxes out at 80.

See https://rt.cpan.org/Public/Bug/Display.html?id=66642 .

  • Participants
  • Parent commits 086aa97

Comments (0)

Files changed (4)

 Revision history for Perl extension XML::LibXML
 
+    - Calculating $err->column() properly, so it won't be maxed out at
+    80:
+        - https://rt.cpan.org/Public/Bug/Display.html?id=66642
+        - the context still maxes at 80 (to avoid wasting RAM) but we
+        still continue past that to get the accurate verdict.
+
 1.72            Thu Jun 16 19:26:13 IDT 2011
     - Removed a stray file from the MANIFEST
         - http://rt.cpan.org/Ticket/Display.html?id=68865
         xmlErrorPtr self
    PREINIT:
         xmlParserInputPtr input;
-	const xmlChar *cur, *base;
+	const xmlChar *cur, *base, *col_cur;
 	unsigned int n, col;	/* GCC warns if signed, because compared with sizeof() */
 	xmlChar  content[81]; /* space for 80 chars + line terminator */
 	xmlChar *ctnt;
         while ((n++ < (sizeof(content)-1)) && (cur > base) && 
 	       (*(cur) != '\n') && (*(cur) != '\r'))
 	  cur--;
+	/* search backwards for beginning-of-line for calculating the
+	 * column. */
+	col_cur = cur;
+	while ((col_cur > base) && (*(col_cur) != '\n') && (*(col_cur) != '\r'))
+	  col_cur--;
 	if ((*(cur) == '\n') || (*(cur) == '\r')) cur++;
+	if ((*(col_cur) == '\n') || (*(col_cur) == '\r')) col_cur++;
 	/* calculate the error position in terms of the current position */
-	col = input->cur - cur;
+	col = input->cur - col_cur;
 	/* search forward for end-of-line (to max buff size) */
 	n = 0;
 	ctnt = content;
 t/43options.t
 t/44extent.t
 t/45regex.t
+t/46err_column.t
 t/60struct_error.t
 t/61error.t
 t/80registryleak.t

File t/46err_column.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# Bug #66642 for XML-LibXML: $err->column() incorrectly maxed out as 80
+# https://rt.cpan.org/Public/Bug/Display.html?id=66642 .
+
+use Test::More tests => 1;
+
+use XML::LibXML qw();
+
+eval {
+    XML::LibXML->new()->parse_string(
+'<foo attr1="value1" attr2="value2" attr3="value2" attr4="value2"'
+. ' attr5="value2" attr6="value2" attr7="value2" attr8="value2"'
+. ' attr9="value2" attr10="value2" attr11="value2" attr12="value2"'
+. ' attr13="value2"attr14="value2" attr15="value2" />'
+    )
+};
+
+# TEST
+is ($@->column(), 203, "Column is OK.");