Przeglądaj źródła

Use first URL seen as the correct URL if it is used with/without a /

sbingner 25 lat temu
rodzic
commit
b5feadc816
1 zmienionych plików z 16 dodań i 3 usunięć
  1. 16 3
      modules/Pisg/Common.pm

+ 16 - 3
modules/Pisg/Common.pm

@@ -13,7 +13,7 @@ use Exporter;
 use strict;
 use strict;
 $^W = 1;
 $^W = 1;
 
 
-my (%aliases, %aliaswilds, %ignored, %aliasseen, %ignored_urls);
+my (%aliases, %aliaswilds, %ignored, %aliasseen, %ignored_urls, %url_seen);
 
 
 # add_alias assumes that the first argument is the true nick and the second is
 # add_alias assumes that the first argument is the true nick and the second is
 # the alias, but will accomidate other arrangements if necessary.
 # the alias, but will accomidate other arrangements if necessary.
@@ -111,8 +111,21 @@ sub match_url
 
 
     if ($str =~ /(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_]+\.[-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/) {
     if ($str =~ /(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_]+\.[-a-zA-Z0-9.,_~=:;&@%?#\/+]+)/) {
         my $url = "$1$2";
         my $url = "$1$2";
-        $url =~ s/\/$//;
-        return $url;
+        if ($url_seen{$url}) {
+            return $url;
+        } elsif ($url =~ s/\/$//) {
+            if ($url_seen{$url}) {
+                return $url;
+            } else {
+                $url_seen{"$url/"} = 1;
+                return "$url/";
+            }
+        } elsif ($url_seen{"$url/"}) {
+            return "$url/";
+        } else {
+            $url_seen{$url} = 1;
+            return $url;
+        }
     }
     }
     return undef;
     return undef;
 }
 }