[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/runtime/kioslave/man
From:       Martin Koller <kollix () aon ! at>
Date:       2011-01-13 20:27:48
Message-ID: 20110113202748.0D41FAC8B3 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1214260 by mkoller:

Do not use pointer into string after 0-byte
Avoid creation of HTML tags inside the title-tag


 M  +34 -7     man2html.cpp  


--- trunk/KDE/kdebase/runtime/kioslave/man/man2html.cpp #1214259:1214260
@@ -1708,7 +1708,7 @@
     }
     c++;
   }
-  else
+  else if ( *c )  // \f alone makes c point at 0-byte
   {
     // \fa Font name with one character or one digit
     // ### HACK do *not* use:  name = *c;  or name would be empty
@@ -2052,11 +2052,13 @@
       curpos++;
       break;
   }
-  if (cplusplus)
+  if (cplusplus && *c)
     c++;
   return c;
 }
 
+//---------------------------------------------------------------------
+
 static char *scan_escape(char *c)
 {
   QByteArray cstr;
@@ -2066,6 +2068,8 @@
   return result;
 }
 
+//---------------------------------------------------------------------
+
 class TABLEROW;
 
 class TABLEITEM
@@ -4433,7 +4437,30 @@
 #endif
             out_html("<TITLE>");
             if ( args.count() )
-              out_html(scan_troff(args[0].data(), 0, NULL));
+            {
+              // work around the problem that in a title no HTML tags are allowed
+              // but args[0] can have formatting escapes, e.g. to switch a font
+              // which results in a HTML tag added to the output
+              char *result = 0;
+              scan_troff(args[0].data(), 0, &result);
+              char *p = result;
+              QByteArray title;
+              while ( *p )
+              {
+                if ( *p == '<' ) // tag begin -> skip whole tag
+                {
+                  for (p++; *p && (*p != '>'); p++) ;
+                  if ( *p ) p++;
+                }
+                if ( *p )
+                  title += *p++;
+              }
+              ignore_links = true;
+              title += '\n';  // needed so that out_html flushes buffer and ignore_links works
+              out_html(title);
+              ignore_links = false;
+              delete [] result;
+            }
             out_html(" Manpage</TITLE>\n");
 
             // KDE defaults.
@@ -4471,24 +4498,24 @@
             out_html("<div><div>\n");
             out_html("<img src=\"help:/common/top-kde.jpg\" alt=\"top-kde\"> ");
             if ( args.count() )
-              out_html(scan_troff(args[0].data(), 0, NULL));
+              scan_troff(args[0].data(), 0, NULL);
             out_html(" - KDE Man Page Viewer");
             out_html("</div></div></div></div>\n");
 
             out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n");
             out_html("<h1>");
             if ( args.count() )
-              out_html(scan_troff(args[0].data(), 0, NULL));
+              scan_troff(args[0].data(), 0, NULL);
             out_html("</h1>\n");
             if (args.count() > 1)
             {
               out_html("Section: ");
               if ( !mandoc_command && (args.count() > 4) )
-                out_html(scan_troff(args[4].data(), 0, NULL));
+                scan_troff(args[4].data(), 0, NULL);
               else
                 out_html(section_name(args[1].data()));
               out_html(" (");
-              out_html(scan_troff(args[1].data(), 0, NULL));
+              scan_troff(args[1].data(), 0, NULL);
               out_html(")\n");
             }
             else
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic