summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Bug.pm
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2009-01-26 22:59:55 +0100
committermkanat%bugzilla.org <>2009-01-26 22:59:55 +0100
commitb3c471cabfb250296df234d8428d31535b5607d9 (patch)
treede797e1f6ba160dad64699fb7e1edd5fcdc319f2 /Bugzilla/Bug.pm
parent503f732b1c64e4c950f747a07dc6cdd056a520ff (diff)
downloadbugzilla-b3c471cabfb250296df234d8428d31535b5607d9.tar.gz
bugzilla-b3c471cabfb250296df234d8428d31535b5607d9.tar.xz
Bug 474902: Allow the Bug URL (See Also) field to also accept Launchpad bug URLs
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=dkl, a=mkanat
Diffstat (limited to 'Bugzilla/Bug.pm')
-rw-r--r--Bugzilla/Bug.pm60
1 files changed, 41 insertions, 19 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index f17d1174d..5038275c8 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -2366,25 +2366,47 @@ sub add_see_also {
ThrowUserError('bug_url_invalid', { url => $input, reason => 'http' });
}
- if ($uri->path !~ /show_bug\.cgi$/) {
- ThrowUserError('bug_url_invalid',
- { url => $input, reason => 'show_bug' });
- }
- my $bug_id = $uri->query_param('id');
- # We don't currently allow aliases, because we can't check to see
- # if somebody's putting both an alias link and a numeric ID link.
- # When we start validating the URL by accessing the other Bugzilla,
- # we can allow aliases.
- detaint_natural($bug_id);
- if (!$bug_id) {
- ThrowUserError('bug_url_invalid', { url => $input, reason => 'id' });
- }
-
- # Make sure that "id" is the only query parameter.
- $uri->query("id=$bug_id");
- # And remove any # part if there is one.
- $uri->fragment(undef);
- my $result = $uri->canonical->as_string;
+ my $result;
+ # Launchpad URLs
+ if ($uri->authority =~ /launchpad.net$/) {
+ # 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.
+ $result = "https://launchpad.net/bugs/$1";
+ }
+ else {
+ ThrowUserError('bug_url_invalid',
+ { url => $input, reason => 'id' });
+ }
+ }
+ # Bugzilla URLs
+ else {
+ if ($uri->path !~ /show_bug\.cgi$/) {
+ ThrowUserError('bug_url_invalid',
+ { url => $input, reason => 'show_bug' });
+ }
+
+ my $bug_id = $uri->query_param('id');
+ # We don't currently allow aliases, because we can't check to see
+ # if somebody's putting both an alias link and a numeric ID link.
+ # When we start validating the URL by accessing the other Bugzilla,
+ # we can allow aliases.
+ detaint_natural($bug_id);
+ if (!$bug_id) {
+ ThrowUserError('bug_url_invalid',
+ { url => $input, reason => 'id' });
+ }
+
+ # Make sure that "id" is the only query parameter.
+ $uri->query("id=$bug_id");
+ # And remove any # part if there is one.
+ $uri->fragment(undef);
+ $result = $uri->canonical->as_string;
+ }
if (length($result) > MAX_BUG_URL_LENGTH) {
ThrowUserError('bug_url_too_long', { url => $result });