Launchpad links from gerrit are truncating the last digit of the bug number.

Bug #1276449 reported by Matthew Gilliard
24
This bug affects 4 people
Affects Status Importance Assigned to Milestone
OpenStack Core Infrastructure
Fix Released
Undecided
Mat Lowery

Bug Description

See my comments in https://review.openstack.org/#/c/60641 - the last digit of the bug number is being dropped so the links are going to the wrong bugs, usually on the wrong project.

summary: - Launchpad links from gerrit are tuncating the last digit of the bug
+ Launchpad links from gerrit are truncating the last digit of the bug
number.
Revision history for this message
clayg (clay-gerrard) wrote :
Revision history for this message
Mat Lowery (mat-lowery) wrote :

Saw this too. Note that this does not occur with https://review-dev.openstack.org.

Revision history for this message
Mat Lowery (mat-lowery) wrote :
Download full text (3.5 KiB)

I think the problem is here: https://github.com/openstack-infra/config/blob/d19e0dd58eea7f075ae4f060872f185205268bcd/modules/openstack_project/manifests/gerrit.pp#L154

I don't understand why the launchpad.net bug URLs need truncating in the first place, but I believe the fix is to change the regex to the following:

<a href=\"(https://bugs\\.launchpad\\.net/[a-zA-Z0-9\\-]+/\\+bug/(\\d+))[^\"]*\">[^<]+</a>

As tested by the following Java:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

    public static void showProblem() {
        System.out.println("Problem");
        String r = "<a href=\"(https://bugs\\.launchpad\\.net/[a-zA-Z0-9\\-]+/\\+bug/(\\d+))[^\"]+\">[^<]+</a>";
        String i = "<a href=\"https://bugs.launchpad.net/trove/+bug/1276858\">https://bugs.launchpad.net/trove/+bug/1276858</a>";
        String i2 = "<a href=\"https://bugs.launchpad.net/trove/+bug/1222891/comments/3\">https://bugs.launchpad.net/trove/+bug/1222891/comments/3</a>";
        Pattern pattern = Pattern.compile(r);
        Matcher matcher = pattern.matcher(i);
        matcher.find();
        System.out.println("Orig: " + i);
        System.out.println(String.format("New: <a href=\"%s\">%s</a>", matcher.group(1), matcher.group(1)));
        matcher = pattern.matcher(i2);
        matcher.find();
        System.out.println("Orig: " + i2);
        System.out.println(String.format("New: <a href=\"%s\">%s</a>", matcher.group(1), matcher.group(1)));
    }

    public static void showSolution() {
        System.out.println("\nSolution");
        String r = "<a href=\"(https://bugs\\.launchpad\\.net/[a-zA-Z0-9\\-]+/\\+bug/(\\d+))[^\"]*\">[^<]+</a>";
        String i = "<a href=\"https://bugs.launchpad.net/trove/+bug/1276858\">https://bugs.launchpad.net/trove/+bug/1276858</a>";
        String i2 = "<a href=\"https://bugs.launchpad.net/trove/+bug/1222891/comments/3\">https://bugs.launchpad.net/trove/+bug/1222891/comments/3</a>";
        Pattern pattern = Pattern.compile(r);
        Matcher matcher = pattern.matcher(i);
        matcher.find();
        System.out.println("Orig: " + i);
        System.out.println(String.format("New: <a href=\"%s\">%s</a>", matcher.group(1), matcher.group(1)));
        matcher = pattern.matcher(i2);
        matcher.find();
        System.out.println("Orig: " + i2);
        System.out.println(String.format("New: <a href=\"%s\">%s</a>", matcher.group(1), matcher.group(1)));
    }

    public static void main(String []args) {
        showProblem();
        showSolution();
    }
}

And its output:

Problem
Orig: <a href="https://bugs.launchpad.net/trove/+bug/1276858">https://bugs.launchpad.net/trove/+bug/1276858</a>
New: <a href="https://bugs.launchpad.net/trove/+bug/127685">https://bugs.launchpad.net/trove/+bug/127685</a>
Orig: <a href="https://bugs.launchpad.net/trove/+bug/1222891/comments/3">https://bugs.launchpad.net/trove/+bug/1222891/comments/3</a>
New: <a href="https://bugs.launchpad.net/trove/+bug/1222891">https://bugs.launchpad.net/trove/+bug/1222891</a>

Solution
Orig: <a href="https://bugs.launchpad.net/trove/+bug/1276858">https://bugs.launchpad.net/trove/+bug/1276858</a>
New: <a href="...

Read more...

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to config (master)

Fix proposed to branch: master
Review: https://review.openstack.org/71743

Changed in openstack-ci:
assignee: nobody → Mat Lowery (mat-lowery)
status: New → In Progress
Revision history for this message
Matthew Gilliard (matthew-gilliard-u) wrote :

Thanks Mat. Possibly the reason for wanting to truncate the URL sometimes is this: https://bugs.launchpad.net/openstack-ci/+bug/1222217 ?

Revision history for this message
Mat Lowery (mat-lowery) wrote :

Hi Matthew. Thanks for the link. I should have paid attention to the git blame. Some points:

* I tested that the regex in my patch set works to drop the period.
* Dropping punctuation at the end of the URL is a common problem, yet the fix is only for bugs.launchpad.net.
* With the regex the way it is, URLs like https://bugs.launchpad.net/trove/+bug/1222891/comments/3 will be truncated for no good reason. Granted, I'm not sure how useful links of this type are.
* Seems like Gerrit's linkify is what should be changed so that it doesn't wrap trailing punctuation in the <a> tag, despite it being a legal URL. They've had similar problems in the past: https://code.google.com/p/gerrit/issues/detail?id=276 but I tested on review-dev.openstack.org and while parentheses and brackets are left out, periods, commas, and exclamation points are all wrapped in the <a> tag.

Revision history for this message
Alexis Lee (alexisl) wrote :

FWIW I'd much rather have trailing punctuation in the URL than vital digits omitted. Let's not overthink this - it's easy enough to include a separating space, EG http://url.com .

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to config (master)

Reviewed: https://review.openstack.org/71743
Committed: https://git.openstack.org/cgit/openstack-infra/config/commit/?id=f9a59e00380746810e237c3b391983e3d86daa46
Submitter: Jenkins
Branch: master

commit f9a59e00380746810e237c3b391983e3d86daa46
Author: Mat Lowery <email address hidden>
Date: Thu Feb 6 23:19:24 2014 -0600

    Fix launchpadbug comment linking in Gerrit

    Change-Id: I4e3dbd0ebc194097db542cfacb79fc2aece64ac6
    Closes-Bug: #1276449

Changed in openstack-ci:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.