dtdparse-discuss
[Top] [All Lists]

[Dtdparse-discuss] Patch for DTD.pm dealing with parameter entity ref in ELEMENT bug

2005-05-27 17:24:32
When trying to parse the Docbook 4.2 XML DTD, dtdparse aborts with
an error at the first ELEMENT declaration.

The problem occurs because the %ho; entity reference is the empty
string, and DTD.pm does not handle the case when it expands to the
empty string when it does a look-ahead check for tag minimization
indicators in an ELEMENT declaration.

The following is a patch to DTD.pm to fix this particular problem.
Including in the patch is the setting of $debug based upon the Debug
level passed to new().  It appears that the code was intended to
allow different debug levels per DTD instance, but the debugging print
statements only check for $debug at the module level.  To avoid
having to fix all debug prints, I just set $debug to whatever Debug
is set to.

--- DTD.pm.org	2005-05-27 13:12:37.562500000 -0500
+++ DTD.pm	2005-05-27 14:01:21.406250000 -0500
@@ -491,7 +491,7 @@
     $self->{'ATTR'} = {};
     $self->{'NOTN'} = {};
     $self->{'VERBOSE'} = $param{'Verbose'} || $param{'Debug'};
-    $self->{'DEBUG'} = $param{'Debug'};
+    $self->debug($param{'Debug'});
     $self->{'TITLE'} = $param{'Title'};
     $self->{'UNEXPANDED_CONTENT'}
       = $param{'UnexpandedContent'} ? 1 : 0;
@@ -618,10 +618,14 @@
 sub debug {
     my $self = shift;
     my $val = shift;
-    my $dbg = $self->{'DEBUG'};
-
-    $self->{'DEBUG'} = $val if defined($val);
+    my $dbg = $debug;
 
+    if (defined($val)) {
+        $debug = $val;
+        if (ref($self)) {
+            $self->{'DEBUG'} = $debug;
+        }
+    }
     return $dbg;
 }
 
@@ -900,7 +904,7 @@
 	    $dtd = $rest . $dtd;
 	    ($etagm, $dtd) = $self->next_token($dtd);
 	} else {
-	    $dtd = $tok . $dtd;
+	    $dtd = $tok . $dtd  if $expand =~ /\S/;
 	}
     } elsif ($tok =~ /^[\-\o]/is) {
 	$stagm = $tok;


<Prev in Thread] Current Thread [Next in Thread>
  • [Dtdparse-discuss] Patch for DTD.pm dealing with parameter entity ref in ELEMENT bug, Earl Hood <=