X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sw-tools/blobdiff_plain/961ce1c2fa0e71e5ffc0c16a1d4fa58802a36a1c..37baafc25e8b2349679c772f11a74b1b011df0a5:/perl/SWMan.pm
diff --git a/perl/SWMan.pm b/perl/SWMan.pm
index 23f0104..4a48eb5 100644
--- a/perl/SWMan.pm
+++ b/perl/SWMan.pm
@@ -1,6 +1,6 @@
# -*-perl-*-
#
-# $Id: SWMan.pm,v 1.1 1999/07/30 18:46:37 mdw Exp $
+# $Id: SWMan.pm,v 1.4 1999/08/24 12:15:34 mdw Exp $
#
# Display and other fiddling of manual pages
#
@@ -28,6 +28,15 @@
#----- Revision history -----------------------------------------------------
#
# $Log: SWMan.pm,v $
+# Revision 1.4 1999/08/24 12:15:34 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.
+#
# Revision 1.1 1999/07/30 18:46:37 mdw
# New CGI script for browsing installed software and documentation.
#
@@ -45,7 +54,7 @@ use SWConfig;
use SWCGI qw(:DEFAULT :layout);
@ISA = qw(Exporter);
-@EXPORT_OK = qw(subst check);
+@EXPORT_OK = qw(subst urlsubst check);
#----- Useful functions -----------------------------------------------------
@@ -100,8 +109,22 @@ sub check($$) {
sub subst($$$) {
my ($s, $n, $sec) = @_;
check($n, $sec) and
- return "$s";
- return "$s";
+ return sprintf("$s",
+ SWCGI::sanitize($n));
+ return $s;
+}
+
+# --- @urlsubst(URL, STRING)@ ---
+#
+# Substitutes in a URL reference. The important bit is that embedded `&'
+# characters are un-entitied from `&'. This doesn't seem to upset
+# Netscape or Lynx as much as I'd expect (or, in fact, at all), but it's
+# slightly untidy.
+
+sub urlsubst($$) {
+ my ($url, $name) = @_;
+ $url =~ s/\&\;/&/;
+ return "$name";
}
# --- @sections()@ ---
@@ -263,8 +286,8 @@ sub man {
# --- Translate the character if it's magical ---
$ch eq "&" and $ch = "&";
- $ch eq "<" and $ch = "<";
- $ch eq ">" and $ch = ">";
+ $ch eq "<" and $ch = "<<";
+ $ch eq ">" and $ch = ">>";
$l .= $ch;
}
$state and $l .= "$state>";
@@ -288,19 +311,24 @@ sub man {
# --- And email and hypertext references too ---
$l =~ s! ((?:\<[bi]\>)*) # Leading highlighting
- ((?:http|ftp) # A protocol name
- :// # The important and obvious bit
- [^]&)\s]+ # Most characters are allowed
- [^]&).,\s\'\"]) # Don't end on punctuation
+ ( \b (?: http s? | ftp | file | news ) # A protocol name
+ : # The important and obvious bit
+ [^]<>)\s<>\'\"]+ # Most characters are allowed
+ [^]<>).,\s<>\'\"]) # Don't end on punctuation
((?:\[bi]\>)*) # Closing tags, optional
- !$&!gx;
+ !urlsubst($2, $&)!egx;
- $l =~ s! ((?:\<[bi]\>)*)
- ( [^\s()&;{}<>,.\`\"] [^\s()&;{}<>\`\"]* \@
- [^\s()&;{}<>\'\"]* [^\s()&;{}<>.,\'\"])
+ $l =~ s! ( (?:\<[bi]\>)* (?:\bmailto:)? )
+ ( [^\s()<>;:{}&<>,.\`\'\"] [^\s()<>;:{}&<>\`\'\"]* \@
+ [^\s()<>;:{&}<>\'\"]* [^\s()<>;:{}&<>.,\'\"])
((?:\[bi]\>)*)
!$&!gx;
+ # --- Fix up the HTML ---
+
+ $l =~ s/\<\;\</g;
+ $l =~ s/\>\>\;/>/g;
+
# --- Done! ---
print $l, "\n";