]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 759030: Clean up Bugzilla::BugUrl modules
authorMatt Selsky <selsky@columbia.edu>
Sun, 17 Jun 2012 12:19:09 +0000 (14:19 +0200)
committerFrédéric Buclin <LpSolit@gmail.com>
Sun, 17 Jun 2012 12:19:09 +0000 (14:19 +0200)
r=timello a=LpSolit

Bugzilla/BugUrl/Debian.pm
Bugzilla/BugUrl/Google.pm
Bugzilla/BugUrl/JIRA.pm
Bugzilla/BugUrl/Launchpad.pm
Bugzilla/BugUrl/MantisBT.pm
Bugzilla/BugUrl/SourceForge.pm
Bugzilla/BugUrl/Trac.pm

index c11a499100b26fbf6014f621d9ac5f5826f2f03d..78397bdd947ee61ee20ec2e0ac33eae1f07ad6af 100644 (file)
@@ -9,16 +9,20 @@ package Bugzilla::BugUrl::Debian;
 use strict;
 use base qw(Bugzilla::BugUrl);
 
-use Bugzilla::Error;
-use Bugzilla::Util;
-
 ###############################
 ####        Methods        ####
 ###############################
 
 sub should_handle {
     my ($class, $uri) = @_;
-    return ($uri->authority =~ /^bugs.debian.org$/i) ? 1 : 0;
+
+    # Debian BTS URLs can look like various things:
+    #   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1234
+    #   http://bugs.debian.org/1234
+    return ($uri->authority =~ /^bugs.debian.org$/i
+            and (($uri->path =~ /bugreport\.cgi$/
+                  and $uri->query_param('bug') =~ m|^\d+$|)
+                 or $uri->path =~ m|^/\d+$|)) ? 1 : 0;
 }
 
 sub _check_value {
@@ -26,24 +30,12 @@ sub _check_value {
 
     my $uri = $class->SUPER::_check_value(@_);
 
-    # Debian BTS URLs can look like various things:
-    #   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1234
-    #   http://bugs.debian.org/1234
-    my $bug_id;
-    if ($uri->path =~ m|^/(\d+)$|) {
-        $bug_id = $1;
-    }
-    elsif ($uri->path =~ /bugreport\.cgi$/) {
-        $bug_id = $uri->query_param('bug');
-        detaint_natural($bug_id);
-    }
-    if (!$bug_id) {
-        ThrowUserError('bug_url_invalid',
-                       { url => $uri->path, reason => 'id' });
-    }
     # This is the shortest standard URL form for Debian BTS URLs,
     # and so we reduce all URLs to this.
-    return new URI("http://bugs.debian.org/" . $bug_id);
+    $uri->path =~ m|^/(\d+)$| || $uri->query_param('bug') =~ m|^(\d+)$|;
+    $uri = new URI("http://bugs.debian.org/$1");
+
+    return $uri;
 }
 
 1;
index 08722c94fbc39656045da1cac8e407f6f1b0d7c9..8b8638c7a0a5a5df634750265716cad3b91604fc 100644 (file)
@@ -9,16 +9,18 @@ package Bugzilla::BugUrl::Google;
 use strict;
 use base qw(Bugzilla::BugUrl);
 
-use Bugzilla::Error;
-use Bugzilla::Util;
-
 ###############################
 ####        Methods        ####
 ###############################
 
 sub should_handle {
     my ($class, $uri) = @_;
-    return ($uri->authority =~ /^code.google.com$/i) ? 1 : 0;
+
+    # Google Code URLs only have one form:
+    #   http(s)://code.google.com/p/PROJECT_NAME/issues/detail?id=1234
+    return ($uri->authority =~ /^code.google.com$/i
+            and $uri->path =~ m|^/p/[^/]+/issues/detail$|
+            and $uri->query_param('id') =~ /^\d+$/) ? 1 : 0;
 }
 
 sub _check_value {
@@ -26,26 +28,13 @@ sub _check_value {
     
     $uri = $class->SUPER::_check_value($uri);
 
-    my $value = $uri->as_string;
-    # Google Code URLs only have one form:
-    #   http(s)://code.google.com/p/PROJECT_NAME/issues/detail?id=1234
-    my $project_name;
-    if ($uri->path =~ m|^/p/([^/]+)/issues/detail$|) {
-        $project_name = $1;
-    } else {
-        ThrowUserError('bug_url_invalid', { url => $value });
-    }
-    my $bug_id = $uri->query_param('id');
-    detaint_natural($bug_id);
-    if (!$bug_id) {
-        ThrowUserError('bug_url_invalid', { url => $value, reason => 'id' });
-    }
     # While Google Code URLs can be either HTTP or HTTPS,
     # always go with the HTTP scheme, as that's the default.
-    $value = "http://code.google.com/p/" . $project_name .
-             "/issues/detail?id=" . $bug_id;
+    if ($uri->scheme eq 'https') {
+        $uri->scheme('http');
+    }
 
-    return new URI($value);
+    return $uri;
 }
 
 1;
index 8a7b90c3e911580443078cb3fbc4e44a36e794fe..f5f7ee5fa92abd61f29b57ad169c69e76c31a50c 100644 (file)
@@ -9,15 +9,16 @@ package Bugzilla::BugUrl::JIRA;
 use strict;
 use base qw(Bugzilla::BugUrl);
 
-use Bugzilla::Error;
-use Bugzilla::Util;
-
 ###############################
 ####        Methods        ####
 ###############################
 
 sub should_handle {
     my ($class, $uri) = @_;
+
+    # JIRA URLs have only one basic form (but the jira is optional):
+    #   https://issues.apache.org/jira/browse/KEY-1234
+    #   http://issues.example.com/browse/KEY-1234
     return ($uri->path =~ m|/browse/[A-Z][A-Z]+-\d+$|) ? 1 : 0;
 }
 
@@ -26,10 +27,6 @@ sub _check_value {
 
     my $uri = $class->SUPER::_check_value(@_);
 
-    # JIRA URLs have only one basic form (but the jira is optional):
-    #   https://issues.apache.org/jira/browse/KEY-1234
-    #   http://issues.example.com/browse/KEY-1234
-
     # Make sure there are no query parameters.
     $uri->query(undef);
     # And remove any # part if there is one.
index 37a238be4cc1533fee87109c198624b1ce2a5241..87fb71a5dc8f5d28415bcae1687a830ad8f3e58b 100644 (file)
@@ -9,15 +9,19 @@ package Bugzilla::BugUrl::Launchpad;
 use strict;
 use base qw(Bugzilla::BugUrl);
 
-use Bugzilla::Error;
-
 ###############################
 ####        Methods        ####
 ###############################
 
 sub should_handle {
     my ($class, $uri) = @_;
-    return ($uri->authority =~ /launchpad.net$/) ? 1 : 0;
+
+    # Launchpad bug URLs can look like various things:
+    #   https://bugs.launchpad.net/ubuntu/+bug/1234
+    #   https://launchpad.net/bugs/1234
+    # All variations end with either "/bugs/1234" or "/+bug/1234"
+    return ($uri->authority =~ /launchpad.net$/
+            and $uri->path =~ m|bugs?/\d+$|) ? 1 : 0;
 }
 
 sub _check_value {
@@ -25,21 +29,12 @@ sub _check_value {
 
     $uri = $class->SUPER::_check_value($uri);
 
-    my $value = $uri->as_string;
-    # Launchpad bug URLs can look like various things:
-    #   https://bugs.launchpad.net/ubuntu/+bug/1234
-    #   https://launchpad.net/bugs/1234
-    # All variations end with either "/bugs/1234" or "/+bug/1234"
-    if ($uri->path =~ m|bugs?/(\d+)$|) {
-        # This is the shortest standard URL form for Launchpad bugs,
-        # and so we reduce all URLs to this.
-        $value = "https://launchpad.net/bugs/$1";
-    }
-    else {
-        ThrowUserError('bug_url_invalid', { url => $value, reason => 'id' });
-    }
-
-    return new URI($value);
+    # This is the shortest standard URL form for Launchpad bugs,
+    # and so we reduce all URLs to this.
+    $uri->path =~ m|bugs?/(\d+)$|;
+    $uri = new URI("https://launchpad.net/bugs/$1");
+
+    return $uri;
 }
 
 1;
index 02a17a64db57d133ac058172f6e1d7c2a066b499..3d49ede69ee5a626e85ecd46c04853de25bd8a60 100644 (file)
@@ -9,15 +9,15 @@ package Bugzilla::BugUrl::MantisBT;
 use strict;
 use base qw(Bugzilla::BugUrl);
 
-use Bugzilla::Error;
-use Bugzilla::Util;
-
 ###############################
 ####        Methods        ####
 ###############################
 
 sub should_handle {
     my ($class, $uri) = @_;
+
+    # MantisBT URLs look like the following ('bugs' directory is optional):
+    #   http://www.mantisbt.org/bugs/view.php?id=1234
     return ($uri->path_query =~ m|view\.php\?id=\d+$|) ? 1 : 0;
 }
 
@@ -26,9 +26,6 @@ sub _check_value {
 
     my $uri = $class->SUPER::_check_value(@_);
 
-    # MantisBT URLs look like the following ('bugs' directory is optional):
-    #   http://www.mantisbt.org/bugs/view.php?id=1234
-
     # Remove any # part if there is one.
     $uri->fragment(undef);
 
index 69d4f98c2b3bb7ffefa30a662db4adfb7db1d90e..11cdd0ff186759596bc23a00668fddfaa7e99bab 100644 (file)
@@ -9,17 +9,21 @@ package Bugzilla::BugUrl::SourceForge;
 use strict;
 use base qw(Bugzilla::BugUrl);
 
-use Bugzilla::Error;
-use Bugzilla::Util;
-
 ###############################
 ####        Methods        ####
 ###############################
 
 sub should_handle {
     my ($class, $uri) = @_;
+
+    # SourceForge tracker URLs have only one form:
+    #  http://sourceforge.net/tracker/?func=detail&aid=111&group_id=111&atid=111
     return ($uri->authority =~ /^sourceforge.net$/i
-            and $uri->path =~ m|/tracker/|) ? 1 : 0;
+            and $uri->path =~ m|/tracker/|
+            and $uri->query_param('func') eq 'detail'
+            and $uri->query_param('aid')
+            and $uri->query_param('group_id')
+            and $uri->query_param('atid')) ? 1 : 0;
 }
 
 sub _check_value {
@@ -27,19 +31,10 @@ sub _check_value {
 
     my $uri = $class->SUPER::_check_value(@_);
 
-    # SourceForge tracker URLs have only one form:
-    #  http://sourceforge.net/tracker/?func=detail&aid=111&group_id=111&atid=111
-    if ($uri->query_param('func') eq 'detail' and $uri->query_param('aid')
-        and $uri->query_param('group_id') and $uri->query_param('atid'))
-    {
-        # Remove any # part if there is one.
-        $uri->fragment(undef);
-        return $uri;
-    }
-    else {
-        my $value = $uri->as_string;
-        ThrowUserError('bug_url_invalid', { url => $value });
-    }
+    # Remove any # part if there is one.
+    $uri->fragment(undef);
+
+    return $uri;
 }
 
 1;
index 500d999095ebad137286a7755a0ef6c0c8597a62..8f6e9cd0e8b01cddb04c4b26db9b6194a704b4da 100644 (file)
@@ -9,15 +9,16 @@ package Bugzilla::BugUrl::Trac;
 use strict;
 use base qw(Bugzilla::BugUrl);
 
-use Bugzilla::Error;
-use Bugzilla::Util;
-
 ###############################
 ####        Methods        ####
 ###############################
 
 sub should_handle {
     my ($class, $uri) = @_;
+
+    # Trac URLs can look like various things:
+    #   http://dev.mutt.org/trac/ticket/1234
+    #   http://trac.roundcube.net/ticket/1484130
     return ($uri->path =~ m|/ticket/\d+$|) ? 1 : 0;
 }
 
@@ -26,10 +27,6 @@ sub _check_value {
 
     my $uri = $class->SUPER::_check_value(@_);
 
-    # Trac URLs can look like various things:
-    #   http://dev.mutt.org/trac/ticket/1234
-    #   http://trac.roundcube.net/ticket/1484130
-
     # Make sure there are no query parameters.
     $uri->query(undef);
     # And remove any # part if there is one.