[PATCH] texi2html: Fix http://texi2html.cvshome.org/issues/show_bug.cgi?id=5

Adrian Aichner <[email protected]> 27 Nov 2001 12:16:08 +0100
Newsgroups gmane.comp.tex.texi2html.devel
Message-ID <[email protected]>
Hi All!

This patch (due to a no-brainer of mine it also contains my former
patch
http://texi2html.cvshome.org/servlets/ReadMsg?msgId=17944&listName=dev)
fixes http://texi2html.cvshome.org/issues/show_bug.cgi?id=5

I'll commit it now and await your verdicts.  Be gentle :-)

I know a patch should not contain a ChangeLog hunk.

Commiting this now will save me considerable work.

I'll be more careful in the future.

Best regards,

Adrian

ChangeLog addition:

2001-11-27  Adrian Aichner  <[email protected]>

	* texi2html.pl (pass5): Improve wording to say "# writing X
	sections ...".
	* texi2html.pl (next_doc): Skip over $docu_top_file and issue
	warning.


texi2html Patch (cvs -f -z3 -q diff -u):

? configure-1.err
? configure-2.err
? dont-search-.-adrian.patch
? make-1.err
Index: ChangeLog
===================================================================
RCS file: /cvs/texi2html/ChangeLog,v
retrieving revision 1.14
diff -u -r1.14 ChangeLog
--- ChangeLog	21 Nov 2001 09:42:33 -0000	1.14
+++ ChangeLog	27 Nov 2001 11:01:01 -0000
@@ -1,3 +1,23 @@
+2001-11-25  Adrian Aichner  <[email protected]>
+
+	* texi2html.init (T2H_InitGlobals): Improve documentation.
+	Prepend $T2H_ADDRESS, which contains nothing but the address now,
+	with "by".
+	* texi2html.init (T2H_DEFAULT_print_page_foot): Prepend
+	$T2H_ADDRESS, which contains nothing but the address now, with
+	"by".
+	* texi2html.init (T2H_PRE_ABOUT): Ditto.
+	* texi2html.init (T2H_AFTER_ABOUT): Make it a lexical.
+	* texi2html.pl: Remove trailing whitespace from lines.  Use
+	protect_html of HREF and NAME.  Use /o where possible in
+	substitutions.
+	* texi2html.pl (T2H_HOMEPAGE): Get rid of newlines.
+	* texi2html.pl (T2H_ADDRESS): Move to texi2html.init.
+	* texi2html.pl (pass1): Fix severe top node matching bug.  
+	* texi2html.pl (do_uref): Don't markup obviously bad uref.
+	* texi2html.pl (t2h_anchor): Use protect_html to allow
+	double-quoting of all html attributes.
+
 2001-11-19  Adrian Aichner  <[email protected]>
 
 	* texi2html.init: Initialize T2H_INCLUDE_DIRS to the empty list.
Index: texi2html.init
===================================================================
RCS file: /cvs/texi2html/texi2html.init,v
retrieving revision 1.7
diff -u -r1.7 texi2html.init
--- texi2html.init	21 Nov 2001 09:42:33 -0000	1.7
+++ texi2html.init	27 Nov 2001 11:01:04 -0000
@@ -857,7 +857,8 @@
 # Layout of standard header and footer
 #
 
-# init routines is before first output is generated
+# This init routine is called at the beginning of pass5 before first
+# output is generated.
 sub T2H_InitGlobals
 {
     # Set the default body text, inserted between <BODY ... >
@@ -867,7 +868,7 @@
     #text inserted before </BODY>
     $T2H_PRE_BODY_CLOSE = '';
     # this is used in footer
-    $T2H_ADDRESS = "by <I>$T2H_USER</I> " if $T2H_USER;
+    $T2H_ADDRESS = "<I>$T2H_USER</I> " if $T2H_USER;
     $T2H_ADDRESS .= "on <I>$T2H_TODAY</I>";
     # this is added inside <HEAD></HEAD> after <TITLE> and some META NAME stuff
     # can be used for <style> <script>, <meta> tags
@@ -909,7 +910,7 @@
 <BR>
 <FONT SIZE="-1">
 This document was generated
-$T2H_ADDRESS
+by $T2H_ADDRESS
 using <A HREF="$T2H_HOMEPAGE"><I>texi2html</I></A>
 </FONT>
 $T2H_PRE_BODY_CLOSE
@@ -1145,11 +1146,11 @@
 # T2H_PRE_ABOUT might be a function
 my $T2H_PRE_ABOUT = <<EOT;
 This document was generated
-$T2H_ADDRESS
+by $T2H_ADDRESS
 using <A HREF=\"$T2H_HOMEPAGE\"><I>texi2html</I></A>
 <P></P>
 EOT
-$T2H_AFTER_ABOUT = '';
+my $T2H_AFTER_ABOUT = '';
 
 sub T2H_DEFAULT_about_body
 {
Index: texi2html.pl
===================================================================
RCS file: /cvs/texi2html/texi2html.pl,v
retrieving revision 1.6
diff -u -r1.6 texi2html.pl
--- texi2html.pl	21 Nov 2001 09:42:33 -0000	1.6
+++ texi2html.pl	27 Nov 2001 11:01:10 -0000
@@ -346,11 +346,9 @@
 # $Id: texi2html.pl,v 1.6 2001/11/21 09:42:33 adrian Exp $
 
 # Homepage:
-$T2H_HOMEPAGE = <<EOT;
-http://texi2html.cvshome.org
-EOT
+$T2H_HOMEPAGE = "http://texi2html.cvshome.org";
 
-# Authors:  
+# Authors:
 $T2H_AUTHORS = <<EOT;
 Written by: Lionel Cons <Lionel.Cons\@cern.ch> (original author)
             Karl Berry  <karl\@freefriends.org>
@@ -360,11 +358,6 @@
 Send bugs and suggestions to <users\@texi2html.cvshome.org>
 EOT
 
-# Address:
-$T2H_ADDRESS = <<EOT;
-by an unknown user
-EOT
-
 # Version: set in configure.in
 $THISVERSION = '@T2H_VERSION@';
 $THISPROG = "texi2html $THISVERSION"; # program name and version
@@ -1547,8 +1540,8 @@
         # weird, a \ at the end of the key results in an error
         # maybe this also broke the dbm database stuff
         $key =~ s|\\$|\\\\|;
-        $value =~ s/\|/\\\|/g;
-        $value =~ s/\\\\\|/\\\|/g;
+        $value =~ s/\|/\\\|/go;
+        $value =~ s/\\\\\|/\\\|/go;
         $value =~ s|\\\\|\\\\\\\\|g;
         print FH "\n\$l2h_cache_key = q/$key/;\n";
         print FH "\$l2h_cache{\$l2h_cache_key} = q|$value|;\n";
@@ -1879,8 +1872,8 @@
         }
         unless ($in_pre)
         {
-            s/``/\"/g;
-            s/''/\"/g;
+            s/``/\"/go;
+            s/''/\"/go;
             s/([\w ])---([\w ])/$1--$2/g;
         }
         #
@@ -1924,7 +1917,9 @@
                 $tag = 'table';
             }
             # special cases
-            if ($tag eq 'top' || ($tag eq 'node' && /^\@node\s+top\b/i))
+            # APA: Fixed regexp to ONLY match the top node, not any
+            # node starting with the word top.
+            if ($tag eq 'top' || ($tag eq 'node' && /^\@node\s+top\s*(,.*)?$/i))
             {
                 $in_top = 1;
                 $has_top = 1;
@@ -1965,8 +1960,8 @@
                     &normalise_node($node_up);
                 }
                 $node =~ /\"/ ?
-                    push @lines, &html_debug("<A NAME='$node'></A>\n", __LINE__) :
-                        push @lines, &html_debug("<A NAME=\"$node\"></A>\n", __LINE__);
+                    push @lines, &html_debug("<A NAME='".protect_html($node)."'></A>\n", __LINE__) :
+                        push @lines, &html_debug("<A NAME=\"".protect_html($node)."\"></A>\n", __LINE__);
                 next;
             }
             elsif ($tag eq 'include')
@@ -2176,7 +2171,7 @@
                 if (/^\@$tag\s*{($NODERE)}\s*$/)
                 {
                     $setref = $1;
-                    $setref =~ s/\s+/ /g; # normalize
+                    $setref =~ s/\s+/ /go; # normalize
                     $setref =~ s/ $//;
                     $node2sec{$setref} = $name;
                     $sec2node{$name} = $setref;
@@ -2484,7 +2479,7 @@
             $_ = $`.$';
             my $anchor = $1;
             $anchor = &normalise_node($anchor);
-            push @lines, &html_debug("<A NAME=\"$anchor\"></A>\n");
+            push @lines, &html_debug("<A NAME=\"".protect_html($anchor)."\"></A>\n");
             $node2href{$anchor} = "$docu_doc#$anchor";
             next INPUT_LINE if $_ =~ /^\s*$/;
         }
@@ -2501,9 +2496,9 @@
         $_ = &protect_html($_) unless $dont_html;
         $dont_html = 0;
         # substitution (unsupported things)
-        s/^\@exdent\s+//g;
-        s/\@noindent\s+//g;
-        s/\@refill\s+//g;
+        s/^\@exdent\s+//go;
+        s/\@noindent\s+//go;
+        s/\@refill\s+//go;
         # other substitutions
         &simple_substitutions;
         s/\@footnote\{/\@footnote$docu_doc\{/g; # mark footnotes, cf. pass 4
@@ -2623,7 +2618,7 @@
                         }
                         else
                         {
-                            push(@lines, &html_debug("<A NAME=\"$docid\"></A>\n",
+                            push(@lines, &html_debug("<A NAME=\"".protect_html($docid)."\"></A>\n",
                                                      __LINE__));
                         }
                         # update DOC
@@ -3010,7 +3005,7 @@
 
     for $letter (@{$page->{Letters}})
     {
-        push @$lines, "<TR><TH><A NAME=\"${name}_$letter\"></A>$letter</TH><TD></TD><TD></TD></TR>\n";
+        push @$lines, "<TR><TH><A NAME=\"".protect_html("${name}_$letter")."\"></A>".protect_html($letter)."</TH><TD></TD><TD></TD></TR>\n";
         for $entry (@{$page->{EntriesByLetter}->{$letter}})
         {
             push @$lines,
@@ -3285,7 +3280,7 @@
                     }
                 }
             }
-            $nodes =~ s/\s+/ /g; # remove useless spaces
+            $nodes =~ s/\s+/ /go; # remove useless spaces
             @args = split(/\s*,\s*/, $nodes);
             $node = $args[0];   # the node is always the first arg
             $node = &normalise_node($node);
@@ -3722,7 +3717,7 @@
     if ($T2H_SPLIT)
     {
         print "# writing " . scalar(@sections) .
-            " sections in $docu_rdir$docu_name"."_[1..$doc_num]"
+            " sections into $docu_rdir$docu_name"."_[1..$doc_num].$docu_ext"
                 if $T2H_VERBOSE;
         $previous = ($T2H_SPLIT eq 'chapter' ? $CHAPTEREND : $SECTIONEND);
         undef $FH;
@@ -4285,7 +4280,7 @@
 sub normalise_node
 {
     local $_ = $_[0];
-    s/\s+/ /g;
+    s/\s+/ /go;
     s/ $//;
     s/^ //;
     &protect_texi;
@@ -4376,7 +4371,11 @@
 sub do_uref
 {
     my($url, $text, $only_text) = split(/,\s*/, $_[0]);
-
+    # APA: Don't markup obviously bad links.
+    # e.g. texinfo.texi 4.0 has this, which would lead to a broken
+    # link:
+    # @section @code{@@uref@{@var{url}[, @var{text}][, @var{replacement}]@}}
+    return if $url =~ /[<>]/;
     $text = $only_text if $only_text;
     $text = $url unless $text;
     &t2h_anchor('', $url, $text);
@@ -4492,12 +4491,12 @@
     my($result);
 
     $result = "<A";
-    $result .= " NAME=\"$name\"" if $name;
+    $result .= " NAME=\"".protect_html($name)."\"" if $name;
     if ($href)
     {
         $href =~ s|^$T2H_HREF_DIR_INSTEAD_FILE|./|
             if ($T2H_HREF_DIR_INSTEAD_FILE);
-        $result .= ($href =~ /\"/ ? " HREF='$href'"  : " HREF=\"$href\"");
+        $result .= " HREF=\"".protect_html($href)."\"";
     }
     $result .= " $extra_attribs" if $extra_attribs;
     $result .= ">$text</A>";
@@ -4519,7 +4518,12 @@
 
 sub next_doc
 {
-    $docu_doc = &doc_href(++$doc_num);
+    ++$doc_num;
+    if ("$docu_rdir${docu_name}_$doc_num.$docu_ext" eq "$docu_top_file") {
+        warn "$WARN Section $docu_rdir${docu_name}_$doc_num.$docu_ext would overwrite Top, continuing at $docu_rdir${docu_name}_".($doc_num+1).".$docu_ext";
+        $doc_num++;
+    }
+    $docu_doc = &doc_href($doc_num);
 }
 
 sub t2h_print_lines
@@ -4560,15 +4564,15 @@
 sub protect_html
 {
     local($what) = @_;
-    # protect & < >
+    # protect &, ", <, and >.
     # APA: Keep it simple.  This is what perl's CGI::espaceHTML does.
     # We may consider using that instead.
     # If raw HTML is used outside @ifhtml or @html it's an error
     # anyway.
-    $what =~ s/\&/\&amp;/g;
-    $what =~ s/\"/\&quot;/g;
-    $what =~ s/\</\&lt;/g;
-    $what =~ s/\>/\&gt;/g;
+    $what =~ s/\&/\&amp;/go;
+    $what =~ s/\"/\&quot;/go;
+    $what =~ s/\</\&lt;/go;
+    $what =~ s/\>/\&gt;/go;
     return($what);
 }
 
@@ -4595,10 +4599,10 @@
     # Character entity references (eg. &lt;)
     # instead of
     # Numeric character references (eg. &#60)
-    $what =~ s/\&amp;/\&/g;
-    $what =~ s/\&quot;/\"/g;
-    $what =~ s/\&lt;/\</g;
-    $what =~ s/\&gt;/\>/g;
+    $what =~ s/\&amp;/\&/go;
+    $what =~ s/\&quot;/\"/go;
+    $what =~ s/\&lt;/\</go;
+    $what =~ s/\&gt;/\>/go;
     return($what);
 }
 
@@ -4606,7 +4610,7 @@
 {
     my $fh = shift;
     my $href = shift || $T2H_HREF{This};
-    $href =~ s/.*#(.*)$/$1/;     
+    $href =~ s/.*#(.*)$/$1/;
     print $fh qq{<A NAME="$href"></A>\n};
 }
 

-- 
Adrian Aichner
 mailto:[email protected]
 http://www.xemacs.org/