[code coverage] Correctly handle diff between patchsets
This CL makes the regular expression correct match the URL when the
page is showing diff between two non-base patchsets.
Bug: 915752
Change-Id: Ie770d46e7dc90c84ee4392b7a82a3ce71de84ebf
diff --git a/src/main/resources/static/chromium-coverage.html b/src/main/resources/static/chromium-coverage.html
index be17021..3ce22b4 100644
--- a/src/main/resources/static/chromium-coverage.html
+++ b/src/main/resources/static/chromium-coverage.html
@@ -41,11 +41,17 @@
const CANARY_HOST_PREFIX = 'canary-';
// Regex used to match the URL path of a Gerrit change view or diff view.
- // Project, change number, patchset number (optional) are required to
- // present in order to match.
- // e.g. '/c/chromium/src/+/1330995/12/base/unguessable_token.cc'.
- // e.g. '/c/chromium/src/+/1330995/12'.
- const DIFF_VIEW_URL_PATTERN = /^\/c\/(.+)\/\+\/(\d+)(?:\/(\d+))?(?:\/.+)?$/;
+ // Project, change number and patchset number (optional) are required to
+ // present in order to match. The URL can be in any of the following forms:
+ // '/c/chromium/src/+/1369646'
+ // '/c/chromium/src/+/1369646/'
+ // '/c/chromium/src/+/1369646/3'
+ // '/c/chromium/src/+/1369646/3/'
+ // '/c/chromium/src/+/1369646/3/base/base/test.cc'
+ // '/c/chromium/src/+/1369646/3/base/base/test.cc/'
+ // Where the patchset number can also be replaced with '3..4'.
+ const GERRIT_URL_PATTERN =
+ /^\/c\/(.+)\/\+\/(\d+)\/?(?:(?:\d+\.\.)?(\d+)\/?)?.*$/;
/**
* Gets and fills infos of the current change such as change number.
@@ -59,7 +65,8 @@
coverageData.host =
coverageData.host.substring(CANARY_HOST_PREFIX.length);
}
- const match = DIFF_VIEW_URL_PATTERN.exec(window.location.pathname);
+
+ const match = GERRIT_URL_PATTERN.exec(window.location.pathname);
if (!match) {
console.log('Fail to parse change info from url for code coverage.');
return;