Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hudson.plugins.git.GitChangeSet;
import hudson.scm.EditType;
import hudson.scm.RepositoryBrowser;
import hudson.Util;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -55,7 +56,7 @@ public URL getDiffLink(GitChangeSet.Path path) throws IOException {
private URL getDiffLinkRegardlessOfEditType(GitChangeSet.Path path) throws IOException {
final GitChangeSet changeSet = path.getChangeSet();
final String pathAsString = path.getPath();
return new URL(getChangeSetLink(changeSet), "#" + pathAsString);
return new URL(getChangeSetLink(changeSet), "#" + Util.rawEncode(pathAsString));
}

/**
Expand All @@ -69,7 +70,7 @@ private URL getDiffLinkRegardlessOfEditType(GitChangeSet.Path path) throws IOExc
public URL getFileLink(GitChangeSet.Path path) throws IOException {
final String pathAsString = path.getPath();
URL url = getUrl();
return encodeURL(new URL(url, url.getPath() + "browse/" + pathAsString));
return encodeURL(new URL(url, url.getPath() + "browse/" + Util.rawEncode(pathAsString)));
}

@Extension @Symbol("bitbucketServer")
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/git/browser/BitbucketWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hudson.plugins.git.GitChangeSet;
import hudson.scm.EditType;
import hudson.scm.RepositoryBrowser;
import hudson.Util;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -55,7 +56,7 @@ public URL getDiffLink(GitChangeSet.Path path) throws IOException {
private URL getDiffLinkRegardlessOfEditType(GitChangeSet.Path path) throws IOException {
final GitChangeSet changeSet = path.getChangeSet();
final String pathAsString = path.getPath();
return new URL(getChangeSetLink(changeSet), "#chg-" + pathAsString);
return new URL(getChangeSetLink(changeSet), "#chg-" + Util.rawEncode(pathAsString));
}

/**
Expand All @@ -69,7 +70,7 @@ private URL getDiffLinkRegardlessOfEditType(GitChangeSet.Path path) throws IOExc
public URL getFileLink(GitChangeSet.Path path) throws IOException {
final String pathAsString = path.getPath();
URL url = getUrl();
return encodeURL(new URL(url, url.getPath() + "history/" + pathAsString));
return encodeURL(new URL(url, url.getPath() + "history/" + Util.rawEncode(pathAsString)));
}

@Extension
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/hudson/plugins/git/browser/GitLab.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import hudson.plugins.git.GitChangeSet.Path;
import hudson.scm.EditType;
import hudson.scm.RepositoryBrowser;
import hudson.Util;
import hudson.util.FormValidation;
import net.sf.json.JSONObject;

Expand Down Expand Up @@ -103,7 +104,7 @@ public URL getDiffLink(Path path) throws IOException {
final GitChangeSet changeSet = path.getChangeSet();
String filelink;
if (getVersionDouble() < 8.0) {
filelink = "#" + path.getPath();
filelink = "#" + Util.rawEncode(path.getPath());
} else {
filelink = "#diff-" + getIndexOfPath(path);
}
Expand All @@ -126,11 +127,11 @@ public URL getFileLink(Path path) throws IOException {
return getDiffLink(path);
} else {
if (getVersionDouble() <= 4.2) {
return encodeURL(new URL(getUrl(), "tree/" + path.getChangeSet().getId() + "/" + path.getPath()));
return encodeURL(new URL(getUrl(), "tree/" + path.getChangeSet().getId() + "/" + Util.rawEncode(path.getPath())));
} else if (getVersionDouble() < 5.1) {
return encodeURL(new URL(getUrl(), path.getChangeSet().getId() + "/tree/" + path.getPath()));
return encodeURL(new URL(getUrl(), path.getChangeSet().getId() + "/tree/" + Util.rawEncode(path.getPath())));
} else {
return encodeURL(new URL(getUrl(), "blob/" + path.getChangeSet().getId() + "/" + path.getPath()));
return encodeURL(new URL(getUrl(), "blob/" + path.getChangeSet().getId() + "/" + Util.rawEncode(path.getPath())));
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/hudson/plugins/git/browser/GitWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import hudson.scm.EditType;
import hudson.scm.RepositoryBrowser;
import hudson.scm.browsers.QueryBuilder;
import hudson.Util;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -62,7 +63,7 @@ public URL getDiffLink(Path path) throws IOException {
}
GitChangeSet changeSet = path.getChangeSet();
URL url = getUrl();
String spec = param(url).add("a=blobdiff").add("f=" + path.getPath()).add("fp=" + path.getPath())
String spec = param(url).add("a=blobdiff").add("f=" + Util.rawEncode(path.getPath())).add("fp=" + Util.rawEncode(path.getPath()))
.add("h=" + path.getSrc()).add("hp=" + path.getDst())
.add("hb=" + changeSet.getId()).add("hpb=" + changeSet.getParentCommit()).toString();
return new URL(url, url.getPath()+spec);
Expand All @@ -79,7 +80,7 @@ public URL getDiffLink(Path path) throws IOException {
public URL getFileLink(Path path) throws IOException {
URL url = getUrl();
String h = (path.getDst() != null) ? path.getDst() : path.getSrc();
String spec = param(url).add("a=blob").add("f=" + path.getPath())
String spec = param(url).add("a=blob").add("f=" + Util.rawEncode(path.getPath()))
.add("h=" + h).add("hb=" + path.getChangeSet().getId()).toString();
return encodeURL(new URL(url, url.getPath()+spec));
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/hudson/plugins/git/browser/GithubWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import hudson.plugins.git.GitChangeSet.Path;
import hudson.scm.EditType;
import hudson.scm.RepositoryBrowser;
import hudson.Util;
import net.sf.json.JSONObject;

import org.jenkinsci.Symbol;
Expand Down Expand Up @@ -80,7 +81,7 @@ public URL getFileLink(Path path) throws IOException {
if (path.getEditType().equals(EditType.DELETE)) {
return getDiffLinkRegardlessOfEditType(path);
} else {
final String spec = "blob/" + path.getChangeSet().getId() + "/" + path.getPath();
final String spec = "blob/" + path.getChangeSet().getId() + "/" + Util.rawEncode(path.getPath());
return encodeURL(buildURL(spec));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class BitbucketServerTest {
private static final String BITBUCKET_URL = "http://bitbucket-server:7990/USER/REPO";
private final BitbucketServer bitbucketServer = new BitbucketServer(BITBUCKET_URL);

private final String path1StrEncoded = "src%2Fmain%2Fjava%2Fhudson%2Fplugins%2Fgit%2Fbrowser%2FGithubWeb.java";
private final String path1StrEncodedPath = "src%252Fmain%252Fjava%252Fhudson%252Fplugins%252Fgit%252Fbrowser%252FGithubWeb.java";
private final String path2StrEncoded = "src%2Ftest%2Fjava%2Fhudson%2Fplugins%2Fgit%2Fbrowser%2FGithubWebTest.java";

@Test
public void testGetUrl() throws IOException {
assertEquals(String.valueOf(bitbucketServer.getUrl()), BITBUCKET_URL + "/");
Expand All @@ -51,11 +55,11 @@ public void testGetDiffLinkPath() throws Exception {
final String path1Str = "src/main/java/hudson/plugins/git/browser/GithubWeb.java";
final Path path1 = pathMap.get(path1Str);

assertEquals(BITBUCKET_URL + "/commits/396fc230a3db05c427737aa5c2eb7856ba72b05d#" + path1Str, bitbucketServer.getDiffLink(path1).toString());

assertEquals(BITBUCKET_URL + "/commits/396fc230a3db05c427737aa5c2eb7856ba72b05d#" + path1StrEncoded, bitbucketServer.getDiffLink(path1).toString());
final String path2Str = "src/test/java/hudson/plugins/git/browser/GithubWebTest.java";
final Path path2 = pathMap.get(path2Str);
assertEquals(BITBUCKET_URL + "/commits/396fc230a3db05c427737aa5c2eb7856ba72b05d#" + path2Str, bitbucketServer.getDiffLink(path2).toString());
assertEquals(BITBUCKET_URL + "/commits/396fc230a3db05c427737aa5c2eb7856ba72b05d#" + path2StrEncoded, bitbucketServer.getDiffLink(path2).toString());
final String path3Str = "src/test/resources/hudson/plugins/git/browser/rawchangelog-with-deleted-file";
final Path path3 = pathMap.get(path3Str);
assertNull("Do not return a diff link for added files.", bitbucketServer.getDiffLink(path3));
Expand All @@ -66,7 +70,7 @@ public void testGetFileLinkPath() throws Exception {
final HashMap<String,Path> pathMap = createPathMap("rawchangelog");
final Path path = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java");
final URL fileLink = bitbucketServer.getFileLink(path);
assertEquals(BITBUCKET_URL + "/browse/src/main/java/hudson/plugins/git/browser/GithubWeb.java", String.valueOf(fileLink));
assertEquals(BITBUCKET_URL + "/browse/" + path1StrEncodedPath, String.valueOf(fileLink));
}

@Test
Expand Down
10 changes: 7 additions & 3 deletions src/test/java/hudson/plugins/git/browser/BitbucketWebTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class BitbucketWebTest {
private static final String BITBUCKET_URL = "http://bitbucket.org/USER/REPO";
private final BitbucketWeb bitbucketWeb = new BitbucketWeb(BITBUCKET_URL);

private final String path1StrEncoded = "src%2Fmain%2Fjava%2Fhudson%2Fplugins%2Fgit%2Fbrowser%2FGithubWeb.java";
private final String path1StrEncodedPath = "src%252Fmain%252Fjava%252Fhudson%252Fplugins%252Fgit%252Fbrowser%252FGithubWeb.java";
private final String path2StrEncoded = "src%2Ftest%2Fjava%2Fhudson%2Fplugins%2Fgit%2Fbrowser%2FGithubWebTest.java";

@Test
public void testGetUrl() throws IOException {
assertEquals(String.valueOf(bitbucketWeb.getUrl()), BITBUCKET_URL + "/");
Expand All @@ -52,11 +56,11 @@ public void testGetDiffLinkPath() throws Exception {
final String path1Str = "src/main/java/hudson/plugins/git/browser/GithubWeb.java";
final Path path1 = pathMap.get(path1Str);

assertEquals(BITBUCKET_URL + "/commits/396fc230a3db05c427737aa5c2eb7856ba72b05d#chg-" + path1Str, bitbucketWeb.getDiffLink(path1).toString());
assertEquals(BITBUCKET_URL + "/commits/396fc230a3db05c427737aa5c2eb7856ba72b05d#chg-" + path1StrEncoded, bitbucketWeb.getDiffLink(path1).toString());

final String path2Str = "src/test/java/hudson/plugins/git/browser/GithubWebTest.java";
final Path path2 = pathMap.get(path2Str);
assertEquals(BITBUCKET_URL + "/commits/396fc230a3db05c427737aa5c2eb7856ba72b05d#chg-" + path2Str, bitbucketWeb.getDiffLink(path2).toString());
assertEquals(BITBUCKET_URL + "/commits/396fc230a3db05c427737aa5c2eb7856ba72b05d#chg-" + path2StrEncoded, bitbucketWeb.getDiffLink(path2).toString());
final String path3Str = "src/test/resources/hudson/plugins/git/browser/rawchangelog-with-deleted-file";
final Path path3 = pathMap.get(path3Str);
assertNull("Do not return a diff link for added files.", bitbucketWeb.getDiffLink(path3));
Expand All @@ -67,7 +71,7 @@ public void testGetFileLinkPath() throws Exception {
final HashMap<String,Path> pathMap = createPathMap("rawchangelog");
final Path path = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java");
final URL fileLink = bitbucketWeb.getFileLink(path);
assertEquals(BITBUCKET_URL + "/history/src/main/java/hudson/plugins/git/browser/GithubWeb.java", String.valueOf(fileLink));
assertEquals(BITBUCKET_URL + "/history/" + path1StrEncodedPath, String.valueOf(fileLink));
}

@Test
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/hudson/plugins/git/browser/GitLabTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class GitLabTest {

private final String SHA1 = "396fc230a3db05c427737aa5c2eb7856ba72b05d";
private final String fileName = "src/main/java/hudson/plugins/git/browser/GithubWeb.java";
private final String encodedFileNameFragment = "src%2Fmain%2Fjava%2Fhudson%2Fplugins%2Fgit%2Fbrowser%2FGithubWeb.java";
private final String encodedFileNamePath = "src%252Fmain%252Fjava%252Fhudson%252Fplugins%252Fgit%252Fbrowser%252FGithubWeb.java";

@Test
public void testGetVersion() {
Expand Down Expand Up @@ -88,8 +90,8 @@ public void testGetChangeSetLinkGitChangeSet() throws Exception {
public void testGetDiffLinkPath() throws Exception {
final HashMap<String, Path> pathMap = createPathMap("rawchangelog");
final Path modified1 = pathMap.get(fileName);
final String expectedPre30 = GITLAB_URL + "commits/" + SHA1 + "#" + fileName;
final String expectedPre80 = GITLAB_URL + "commit/" + SHA1 + "#" + fileName;
final String expectedPre30 = GITLAB_URL + "commits/" + SHA1 + "#" + encodedFileNameFragment;
final String expectedPre80 = GITLAB_URL + "commit/" + SHA1 + "#" + encodedFileNameFragment;
final String expectedURL = GITLAB_URL + "commit/" + SHA1 + "#" + "diff-0";
final String expectedDefault = expectedURL;
assertEquals(expectedPre30, gitlabNegative.getDiffLink(modified1).toString());
Expand All @@ -111,9 +113,9 @@ public void testGetDiffLinkPath() throws Exception {
public void testGetFileLinkPath() throws Exception {
final HashMap<String, Path> pathMap = createPathMap("rawchangelog");
final Path path = pathMap.get(fileName);
final String expectedURL = GITLAB_URL + "blob/396fc230a3db05c427737aa5c2eb7856ba72b05d/" + fileName;
final String expectedURL = GITLAB_URL + "blob/396fc230a3db05c427737aa5c2eb7856ba72b05d/" + encodedFileNamePath;
final String expectedV29 = expectedURL.replace("blob/", "tree/");
final String expectedV50 = GITLAB_URL + "396fc230a3db05c427737aa5c2eb7856ba72b05d/tree/" + fileName;
final String expectedV50 = GITLAB_URL + "396fc230a3db05c427737aa5c2eb7856ba72b05d/tree/" + encodedFileNamePath;
assertEquals(expectedV29, gitlabNegative.getFileLink(path).toString());
assertEquals(expectedV29, gitlab29.getFileLink(path).toString());
assertEquals(expectedV29, gitlab42.getFileLink(path).toString());
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/hudson/plugins/git/browser/GitWebTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class GitWebTest {
private static final String GITWEB_URL = "https://SERVER/gitweb?repo.git";
private final GitWeb gitwebWeb = new GitWeb(GITWEB_URL);

private final String encodedFileNameQuery = "src%2Fmain%2Fjava%2Fhudson%2Fplugins%2Fgit%2Fbrowser%2FGithubWeb.java";
private final String encodedFileNameQueryDouble = "src%252Fmain%252Fjava%252Fhudson%252Fplugins%252Fgit%252Fbrowser%252FGithubWeb.java";

@Test
public void testGetUrl() throws IOException {
assertEquals(String.valueOf(gitwebWeb.getUrl()), GITWEB_URL);
Expand All @@ -39,15 +42,15 @@ public void testGetChangeSetLinkGitChangeSet() throws Exception {
public void testGetDiffLinkPath() throws Exception {
final HashMap<String, Path> pathMap = createPathMap("rawchangelog");
final Path modified1 = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java");
assertEquals(GITWEB_URL + "&a=blobdiff&f=src/main/java/hudson/plugins/git/browser/GithubWeb.java&fp=src/main/java/hudson/plugins/git/browser/GithubWeb.java&h=3f28ad75f5ecd5e0ea9659362e2eef18951bd451&hp=2e0756cd853dccac638486d6aab0e74bc2ef4041&hb=396fc230a3db05c427737aa5c2eb7856ba72b05d&hpb=f28f125f4cc3e5f6a32daee6a26f36f7b788b8ff", gitwebWeb.getDiffLink(modified1).toString());
assertEquals(GITWEB_URL + "&a=blobdiff&f=" + encodedFileNameQuery + "&fp=" + encodedFileNameQuery + "&h=3f28ad75f5ecd5e0ea9659362e2eef18951bd451&hp=2e0756cd853dccac638486d6aab0e74bc2ef4041&hb=396fc230a3db05c427737aa5c2eb7856ba72b05d&hpb=f28f125f4cc3e5f6a32daee6a26f36f7b788b8ff", gitwebWeb.getDiffLink(modified1).toString());
}

@Test
public void testGetFileLinkPath() throws Exception {
final HashMap<String, Path> pathMap = createPathMap("rawchangelog");
final Path path = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java");
final URL fileLink = gitwebWeb.getFileLink(path);
assertEquals(GITWEB_URL + "&a=blob&f=src/main/java/hudson/plugins/git/browser/GithubWeb.java&h=2e0756cd853dccac638486d6aab0e74bc2ef4041&hb=396fc230a3db05c427737aa5c2eb7856ba72b05d", String.valueOf(fileLink));
assertEquals(GITWEB_URL + "&a=blob&f=" + encodedFileNameQueryDouble + "&h=2e0756cd853dccac638486d6aab0e74bc2ef4041&hb=396fc230a3db05c427737aa5c2eb7856ba72b05d", String.valueOf(fileLink));
}

@Test
Expand Down
Loading
Loading