pmccabe2html: escaping of special characters
authorMats Erik Andersson <gnu@gisladisker.se>
Wed, 25 Sep 2013 20:27:03 +0000 (22:27 +0200)
committerPádraig Brady <P@draigBrady.com>
Wed, 25 Sep 2013 23:44:17 +0000 (00:44 +0100)
The C code characters '<', '>', and '&' were improperly
escaped in HTML output, and their multiplicity was ignored.

ChangeLog
build-aux/pmccabe2html

index 211d296..770710c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2013-09-25  Mats Erik Andersson  <gnu@gisladisker.se>
+
+       pmccabe2html: escaping of special characters
+       Escape all '<', '>', and '&' in HTML output.
+       * build-aux/pmccabe2html (html_fnc): Call gsub()
+       instead of sub() to capture all '<', '>', and '&'.
+       Neither of '<' and '>' is special in a regexp,
+       so first arguments to gsub() are corrected. Also,
+       in replacement strings, ampersand must be escaped.
+       Finally, '&' must be handled first, then '<' and '>'.
+
 2013-09-24  Eric Blake  <eblake@redhat.com>
 
        manywarnings: enable nicer gcc warning messages
index 094c3e9..ffd0788 100644 (file)
@@ -422,9 +422,9 @@ function html_fnc (nfun,
 
             while ((getline codeline < (fname nfun "_fn.txt")) > 0)
             {
-                sub(/\\</, "&lt;", codeline)
-                sub(/\\>/, "&gt;", codeline)
-                sub(/&/, "&amp;", codeline)
+                gsub(/&/, "\&amp;", codeline)  # Must come first.
+                gsub(/</, "\&lt;", codeline)
+                gsub(/>/, "\&gt;", codeline)
 
                 print codeline
             }