From 5e0915466c15ea7e55e691d19d4d023933f3be6a Mon Sep 17 00:00:00 2001 From: "terry%netscape.com" <> Date: Fri, 26 Mar 1999 10:34:12 +0000 Subject: Redo the linkifying of URLs and email addresses to not munge up weird cases so badly. --- bug_form.pl | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'bug_form.pl') diff --git a/bug_form.pl b/bug_form.pl index e8bc30ec3..360c55bbc 100644 --- a/bug_form.pl +++ b/bug_form.pl @@ -21,7 +21,62 @@ use diagnostics; use strict; -use HTML::FromText; + +# This routine quoteUrls contains inspirations from the HTML::FromText CPAN +# module by Gareth Rees . It has been heavily hacked, +# all that is really recognizable from the original is bits of the regular +# expressions. + +sub quoteUrls { + my $text = shift; # Take a copy; don't modify in-place. + return $text unless $text; + + my $protocol = join '|', + qw(afs cid ftp gopher http https mid news nntp prospero telnet wais); + + my %options = ( metachars => 1, @_ ); + + my $count = 0; + + # Now, quote any "#" characters so they won't confuse stuff later + $text =~ s/#/%#/g; + + # Next, find anything that looks like a URL or an email address and + # pull them out the the text, replacing them with a "#### + # marker, and writing them into an array. All this confusion is + # necessary so that we don't match on something we've already replaced, + # which can happen if you do multiple s///g operations. + + my @things; + while ($text =~ s%((mailto:)?([\w\.\-\+\=]+\@\w+(?:\.\w+)+)\b| + (\b((?:$protocol):\S+[\w/])))%"##".$count."##"%exo) { + my $item = $&; + + $item = value_quote($item); + + if ($item !~ m/^$protocol:/o && $item !~ /^mailto:/) { + # We must have grabbed this one because it looks like an email + # address. + $item = qq{$item}; + } else { + $item = qq{$item}; + } + + $things[$count++] = $item; + } + + $text = value_quote($text); + + # Stuff everything back from the array. + for (my $i=0 ; $i<$count ; $i++) { + $text =~ s/##$i##/$things[$i]/e; + } + + # And undo the quoting of "#" characters. + $text =~ s/%#/#/g; + + return $text; +} quietly_check_login(); @@ -309,7 +364,7 @@ print "
 ";
-print text2html($bug{'long_desc'}, email=>1, urls=>1);
+print quoteUrls($bug{'long_desc'}, email=>1, urls=>1);
 print "
 

\n"; -- cgit v1.2.3-24-g4f1b