X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sw-tools/blobdiff_plain/44b3c5890c87bc795256cd75bdd32d4279336aa9..37baafc25e8b2349679c772f11a74b1b011df0a5:/perl/SWInfo.pm diff --git a/perl/SWInfo.pm b/perl/SWInfo.pm index 276ac05..c4cf7bb 100644 --- a/perl/SWInfo.pm +++ b/perl/SWInfo.pm @@ -1,6 +1,6 @@ # -*-perl-*- # -# $Id: SWInfo.pm,v 1.2 1999/08/18 17:10:07 mdw Exp $ +# $Id: SWInfo.pm,v 1.4 1999/08/24 12:15:33 mdw Exp $ # # Read and output GNU Info files # @@ -28,6 +28,12 @@ #----- Revision history ----------------------------------------------------- # # $Log: SWInfo.pm,v $ +# Revision 1.4 1999/08/24 12:15:33 mdw +# Properly sanitize CGI arguments (like `gtk+'). +# +# Revision 1.3 1999/08/19 12:11:10 mdw +# More improvements to URL recognizer. +# # Revision 1.2 1999/08/18 17:10:07 mdw # Slight improvements to URL and email address parsing. # @@ -77,11 +83,10 @@ sub subst($$$) { # --- Transform it into something that won't get mangled --- - $node =~ s/[+&=%]|[^ -~]/sprintf("%%%02x", ord($&))/eg; - $node =~ tr/ /+/; + $node = SWCGI::sanitize($node); ($dir = $i->{dir}) =~ s:$C{prefix}/info/?::; - $dir = "&dir=$dir" if $dir; + $dir = "&dir=" . SWCGI::sanitize($dir) if $dir; return "$oref$tail"; } @@ -109,8 +114,8 @@ sub info { # --- Now translate the node into HTML, first line first --- $n =~ s/\&/&/; - $n =~ s/\/>/; + $n =~ s/\/>>/; $n =~ s/\A( [^\n]* Next:\ *) ([^,\n]*) / $1 . subst($2, $file, $i) /eix; $n =~ s/\A( [^\n]* Prev:\ *) ([^,\n]*) / $1 . subst($2, $file, $i) /eix; $n =~ s/\A( [^\n]* Up:\ *) ([^,\n]*) / $1 . subst($2, $file, $i) /eix; @@ -144,9 +149,29 @@ sub info { } $out .= $n; - $out =~ s!\b(https?|ftp|file|news):[^]&)\s]*[^]&).,\s\'\"]!$&!g; - $out =~ s!(?:\bmailto:)?([^\s()&;:{}.,\`\"][^\s()&;:{}\`\"]*\@[^\s()&;:{}\'\"]*[^\s()&;:{}.,\'\"])!$&!g; - $out =~ s!([-_.\w]+)\((\d+\w*)\)!SWMan::subst("$1($2)", $1, $2)!eg; + # --- Spot URLs (except `mailto') --- + + $out =~ s! \b (http s? | ftp | file | news) : + [^]<>)\s]* [^]<>).,\s\'] + !urlsubst($&, $&)!egx; + + # --- Spot email addresses (including `mailto' URLs) --- + + $out =~ s! (?:\bmailto:)? + ([^\s()<>&;:{}.,\`\'\"] [^\s()<>&;:{}\`\'\"]* + \@ + [^\s()<>&;:{}\'\"]* [^\s()<>&;:{}.,\'\"]) + !$&!gx; + + # --- Spot manpage references --- + + $out =~ s! ([-_.\w]+) \( (\d+\w*) \) + !SWMan::subst("$1($2)", $1, $2)!egx; + + # --- Fix up the HTML --- + + $out =~ s/\<\\>/>/g; header("Info: ($file)$node"); print("
\n$out
\n");