Comment 3 for bug 1276449

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

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="https://bugs.launchpad.net/trove/+bug/1276858">https://bugs.launchpad.net/trove/+bug/1276858</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>