diff --git a/core/src/main/java/hudson/scm/browsers/ViewSVN.java b/core/src/main/java/hudson/scm/browsers/ViewSVN.java
index f717a93523..aaf12cb7ed 100644
--- a/core/src/main/java/hudson/scm/browsers/ViewSVN.java
+++ b/core/src/main/java/hudson/scm/browsers/ViewSVN.java
@@ -1,19 +1,17 @@
package hudson.scm.browsers;
-import hudson.scm.SubversionRepositoryBrowser;
+import hudson.model.Descriptor;
+import hudson.scm.ChangeLogSet.Entry;
import hudson.scm.RepositoryBrowser;
import hudson.scm.SubversionChangeLogSet;
-import hudson.scm.ChangeLogSet.Entry;
import hudson.scm.SubversionChangeLogSet.Path;
-import hudson.model.Descriptor;
-
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.io.IOException;
-import java.text.MessageFormat;
-
-import org.kohsuke.stapler.StaplerRequest;
+import hudson.scm.SubversionRepositoryBrowser;
import static hudson.scm.browsers.ViewCVS.trimHeadSlash;
+import org.kohsuke.stapler.StaplerRequest;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
/**
* {@link RepositoryBrowser} for Subversion.
@@ -26,6 +24,8 @@ public class ViewSVN extends SubversionRepositoryBrowser {
* The URL of the top of the site.
*
* Normalized to ends with '/', like http://svn.apache.org/viewvc/
+ * It may contain a query parameter like ?root=foobar, so relative URL
+ * construction needs to be done with care.
*/
public final URL url;
@@ -41,19 +41,21 @@ public class ViewSVN extends SubversionRepositoryBrowser {
@Override
public URL getDiffLink(Path path) throws IOException {
int r = path.getLogEntry().getRevision();
- return new URL(getFileLink(path),
- MessageFormat.format("?r1={0}&r2={1}",r-1,r));
+ return new URL(url,trimHeadSlash(path.getValue())+param().add("r1="+(r-1)).add("r2="+r));
}
@Override
public URL getFileLink(Path path) throws IOException {
- return new URL(url,trimHeadSlash(path.getValue()));
+ return new URL(url,trimHeadSlash(path.getValue())+param());
}
@Override
public URL getChangeSetLink(Entry changeSet) throws IOException {
- return new URL(url,"?view=rev&revision="+
- ((SubversionChangeLogSet.LogEntry)changeSet).getRevision());
+ return new URL(url,"."+param().add("view=rev").add("revision="+((SubversionChangeLogSet.LogEntry)changeSet).getRevision()));
+ }
+
+ private QueryBuilder param() {
+ return new QueryBuilder(url.getQuery());
}
public Descriptor getDescriptor() {