Fix edit link when base URL has a path
On a setup having a path prefix such as `/r` the edit link woud be
broken because the prefix is stripped.
The reason is `URI.resolve()` is given an absolute path which strip the
path from the base URI:
jshell> new URI("https://example.org/r").resolve("/admin/repos/edit");
^^
$2 ==> https://example.org/admin/repos/edit
^^^____oops
Which is consistent with python `os.path`:
>>> os.path.join('https://example.org/r', '/admin/repos/edit');
'/admin/repos/edit'
Remove the leading slash from the edit URI and update the test with the
proper expected value.
Bug: https://phabricator.wikimedia.org/T405481
Change-Id: I98e9d89cbc4850270f81b52665f2c8849f25c879
diff --git a/java/com/google/gitiles/PathServlet.java b/java/com/google/gitiles/PathServlet.java
index b2563b0..a5c46e2 100644
--- a/java/com/google/gitiles/PathServlet.java
+++ b/java/com/google/gitiles/PathServlet.java
@@ -553,7 +553,7 @@
URI editUrl = new URI(baseGerritUrl);
String path =
String.format(
- "/admin/repos/edit/repo/%s/branch/%s/file/%s",
+ "admin/repos/edit/repo/%s/branch/%s/file/%s",
view.getRepositoryName(), commitish, view.getPathPart());
return editUrl.resolve(escapeName(path));
} catch (URISyntaxException use) {
diff --git a/javatests/com/google/gitiles/PathServletTest.java b/javatests/com/google/gitiles/PathServletTest.java
index 660cc2f..966d7e9 100644
--- a/javatests/com/google/gitiles/PathServletTest.java
+++ b/javatests/com/google/gitiles/PathServletTest.java
@@ -111,7 +111,7 @@
String editUrl = (String) getBlobData(data).get("editUrl");
String testUrl =
- "http://test-host-review/admin/repos/edit/repo/repo/branch/refs/heads/master/file/editFoo";
+ "http://test-host-review/path-prefix/admin/repos/edit/repo/repo/branch/refs/heads/master/file/editFoo";
assertThat(editUrl).isEqualTo(testUrl);
}