From dd56cd85715d0b8f6d9dfaca468f9589868cbded Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Wed, 4 Nov 2020 20:35:31 +0100 Subject: raw: Strip leading and trailing slash from repo and path names for link When creating a link for raw display, a trailing slash is stripped from the end of the base URL. Also do this for the repository, as well as stripping leading slashes from the repository and the path values. --- src/main/java/com/gitblit/servlet/RawServlet.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/main/java/com/gitblit') diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index dca57730..5fba78b5 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -99,6 +99,12 @@ public class RawServlet extends HttpServlet { if (baseURL.length() > 0 && baseURL.charAt(baseURL.length() - 1) == '/') { baseURL = baseURL.substring(0, baseURL.length() - 1); } + if (repository.length() > 0 && repository.charAt(repository.length() - 1) == '/') { + repository = repository.substring(0, repository.length() - 1); + } + if (repository.length() > 0 && repository.charAt(0) == '/') { + repository = repository.substring(1); + } char fsc = '!'; char c = GitblitContext.getManager(IRuntimeManager.class).getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); @@ -109,6 +115,9 @@ public class RawServlet extends HttpServlet { branch = Repository.shortenRefName(branch).replace('/', fsc); } + if (path != null && path.length() > 0 && path.charAt(0) == '/') { + path = path.substring(1); + } String encodedPath = path == null ? "" : path.replace('/', fsc); return baseURL + Constants.RAW_PATH + repository + "/" + (branch == null ? "" : (branch + "/" + encodedPath)); } -- cgit v1.2.3 From 23943971846437c8bc24504d3bd4b681edea5433 Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Sat, 7 Nov 2020 19:56:51 +0100 Subject: raw: Fix exceptions when no path info is given to raw servlet --- src/main/java/com/gitblit/servlet/RawServlet.java | 5 +- .../java/com/gitblit/servlet/RawServletTest.java | 112 ++++++++++++++++++++- 2 files changed, 115 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/gitblit') diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index 5fba78b5..211d847d 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -124,6 +124,7 @@ public class RawServlet extends HttpServlet { protected String getBranch(String repository, HttpServletRequest request) { String pi = request.getPathInfo(); + if (pi == null || pi.isEmpty() || pi.equals("/")) return ""; String branch = pi.substring(pi.indexOf(repository) + repository.length() + 1); int fs = branch.indexOf('/'); if (fs > -1) { @@ -135,7 +136,9 @@ public class RawServlet extends HttpServlet { protected String getPath(String repository, String branch, HttpServletRequest request) { String base = repository + "/" + branch; - String pi = request.getPathInfo().substring(1); + String pi = request.getPathInfo(); + if (pi == null || pi.isEmpty() || pi.equals("/")) return ""; + pi = pi.substring(1); if (pi.equals(base)) { return ""; } diff --git a/src/test/java/com/gitblit/servlet/RawServletTest.java b/src/test/java/com/gitblit/servlet/RawServletTest.java index 9f2b9e71..1deacf7e 100644 --- a/src/test/java/com/gitblit/servlet/RawServletTest.java +++ b/src/test/java/com/gitblit/servlet/RawServletTest.java @@ -3,6 +3,7 @@ package com.gitblit.servlet; import com.gitblit.Constants; import com.gitblit.IStoredSettings; import com.gitblit.Keys; +import com.gitblit.manager.IRepositoryManager; import com.gitblit.tests.mock.MockGitblitContext; import com.gitblit.tests.mock.MockRuntimeManager; import org.junit.Before; @@ -10,20 +11,28 @@ import org.junit.BeforeClass; import org.junit.Test; +import javax.servlet.http.HttpServletRequest; + import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class RawServletTest { private final static String FSC = "!"; + private static MockRuntimeManager mockRuntimeManager = new MockRuntimeManager(); private static IStoredSettings settings; + private IRepositoryManager repositoryMngr; + + private RawServlet rawServlet; + @BeforeClass public static void init() { MockGitblitContext gitblitContext = new MockGitblitContext(); - MockRuntimeManager mockRuntimeManager = new MockRuntimeManager(); gitblitContext.addManager(mockRuntimeManager); settings = mockRuntimeManager.getSettings(); } @@ -32,6 +41,9 @@ public class RawServletTest public void setUp() { settings.overrideSetting(Keys.web.forwardSlashCharacter, "/"); + + repositoryMngr = mock(IRepositoryManager.class); + rawServlet = new RawServlet(mockRuntimeManager, repositoryMngr); } @@ -672,4 +684,102 @@ public class RawServletTest public void getPath() { } + + @Test + public void getBranch_Repo() + { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getPathInfo()).thenReturn("/test.git/"); + + String branch = rawServlet.getBranch("test.git", request); + + assertEquals("Branch was supposed to be empty as no branch was given.", "", branch); + } + + @Test + public void getBranch_RepoNoTrailingSlash() + { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getPathInfo()).thenReturn("/test.git"); + + String branch = rawServlet.getBranch("test.git", request); + + assertEquals("Branch was supposed to be empty as no branch was given.", "", branch); + } + + @Test + public void getBranch_PiNull() + { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getPathInfo()).thenReturn(null); + + String branch = rawServlet.getBranch("test.git", request); + + assertEquals("Branch was supposed to be empty as path info is null.", "", branch); + } + + + @Test + public void getBranch_PiEmpty() + { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getPathInfo()).thenReturn(""); + + String branch = rawServlet.getBranch("test.git", request); + + assertEquals("Branch was supposed to be empty as no path info exists.", "", branch); + } + + + + + + + + + @Test + public void getPath_Repo() + { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getPathInfo()).thenReturn("/test.git/"); + + String path = rawServlet.getPath("test.git", "", request); + + assertEquals("Path was supposed to be empty as no path was given.", "", path); + } + + @Test + public void getPath_RepoNoTrailingSlash() + { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getPathInfo()).thenReturn("/test.git"); + + String path = rawServlet.getPath("test.git", "", request); + + assertEquals("Path was supposed to be empty as no path was given.", "", path); + } + + @Test + public void getPath_PiNull() + { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getPathInfo()).thenReturn(null); + + String path = rawServlet.getPath("test.git", "", request); + + assertEquals("Path was supposed to be empty as path info is null.", "", path); + } + + + @Test + public void getPath_PiEmpty() + { + HttpServletRequest request = mock(HttpServletRequest.class); + when(request.getPathInfo()).thenReturn(""); + + String path = rawServlet.getPath("test.git", "", request); + + assertEquals("Path was supposed to be empty as no path info exists.", "", path); + } + } -- cgit v1.2.3 From 26db31876aaf59651bb8b8a0b65bb4865f090788 Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Sun, 8 Nov 2020 17:19:35 +0100 Subject: raw: Refactor RawServlet:getBranch and :getPath parameters Refactor the `getBranch` and `getPath` methods to take a String as second parameter, which is the already sanitised path info. Don't get the path info from a passed in request anymore. The methods are only ever called from within `processRequest`, which already does some checks on the path info, like removing a leading slash character. So no need to do that every time again the methods and passing a request for that. --- .../java/com/gitblit/servlet/PagesServlet.java | 7 +- src/main/java/com/gitblit/servlet/RawServlet.java | 50 +- .../java/com/gitblit/servlet/RawServletTest.java | 729 +++++++++++++++++++-- 3 files changed, 727 insertions(+), 59 deletions(-) (limited to 'src/main/java/com/gitblit') diff --git a/src/main/java/com/gitblit/servlet/PagesServlet.java b/src/main/java/com/gitblit/servlet/PagesServlet.java index 1473e966..a76a50b5 100644 --- a/src/main/java/com/gitblit/servlet/PagesServlet.java +++ b/src/main/java/com/gitblit/servlet/PagesServlet.java @@ -69,13 +69,14 @@ public class PagesServlet extends RawServlet { } @Override - protected String getBranch(String repository, HttpServletRequest request) { + String getBranch(String repository, String pathInfo) + { return "gh-pages"; } @Override - protected String getPath(String repository, String branch, HttpServletRequest request) { - String pi = request.getPathInfo().substring(1); + String getPath(String repository, String branch, String pi) + { if (pi.equals(repository)) { return ""; } diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index 211d847d..8213850a 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -122,10 +122,23 @@ public class RawServlet extends HttpServlet { return baseURL + Constants.RAW_PATH + repository + "/" + (branch == null ? "" : (branch + "/" + encodedPath)); } - protected String getBranch(String repository, HttpServletRequest request) { - String pi = request.getPathInfo(); - if (pi == null || pi.isEmpty() || pi.equals("/")) return ""; - String branch = pi.substring(pi.indexOf(repository) + repository.length() + 1); + + /** + * Find and return the name of a branch from a given repository in a HTTP request path info. + * The branch name returned is transformed to the form in the repository, i.e. a transformation + * of the forward slash character in the URL is reversed. + * + * @param repository + * Path of repository, no leading slash, no trailing slash + * @param pathInfo + * The sanitised path info from a HTTP request, i.e. without the leading slash. + * + * @return The name of the branch from the path info, unescaped. + */ + String getBranch(String repository, String pathInfo) + { + if (pathInfo == null || pathInfo.isEmpty() || pathInfo.equals("/")) return ""; + String branch = pathInfo.substring(pathInfo.indexOf(repository) + repository.length() + 1); int fs = branch.indexOf('/'); if (fs > -1) { branch = branch.substring(0, fs); @@ -134,15 +147,28 @@ public class RawServlet extends HttpServlet { return branch.replace('!', '/').replace(c, '/'); } - protected String getPath(String repository, String branch, HttpServletRequest request) { + /** + * Find and return the path from a given repository and given branch in a HTTP request path info. + * The path string returned is transformed to the form in the repository, i.e. a transformation + * of the forward slash character in the URL is reversed. + * + * @param repository + * Path of repository, no leading slash, no trailing slash + * @param branch + * Branch name from the repository, i.e. with forward slash character, no leading slash, no trailing slash. + * @param pathInfo + * The sanitised path info from a HTTP request, i.e. without the leading slash. + * + * @return The file/folder path part from the path info, in unescaped form. + */ + String getPath(String repository, String branch, String pathInfo) + { + if (pathInfo == null || pathInfo.isEmpty() || pathInfo.equals("/")) return ""; String base = repository + "/" + branch; - String pi = request.getPathInfo(); - if (pi == null || pi.isEmpty() || pi.equals("/")) return ""; - pi = pi.substring(1); - if (pi.equals(base)) { + if (pathInfo.equals(base)) { return ""; } - String path = pi.substring(pi.indexOf(base) + base.length() + 1); + String path = pathInfo.substring(pathInfo.indexOf(base) + base.length() + 1); if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } @@ -200,7 +226,7 @@ public class RawServlet extends HttpServlet { } // identify the branch - String branch = getBranch(repository, request); + String branch = getBranch(repository, path); if (StringUtils.isEmpty(branch)) { branch = r.getBranch(); if (branch == null) { @@ -219,7 +245,7 @@ public class RawServlet extends HttpServlet { } // identify the requested path - String requestedPath = getPath(repository, branch, request); + String requestedPath = getPath(repository, branch, path); // identify the commit RevCommit commit = JGitUtils.getCommit(r, branch); diff --git a/src/test/java/com/gitblit/servlet/RawServletTest.java b/src/test/java/com/gitblit/servlet/RawServletTest.java index 1deacf7e..dac9896e 100644 --- a/src/test/java/com/gitblit/servlet/RawServletTest.java +++ b/src/test/java/com/gitblit/servlet/RawServletTest.java @@ -8,18 +8,16 @@ import com.gitblit.tests.mock.MockGitblitContext; import com.gitblit.tests.mock.MockRuntimeManager; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; -import javax.servlet.http.HttpServletRequest; - import static org.junit.Assert.*; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class RawServletTest { - private final static String FSC = "!"; + private static final String FSC = "!"; private static MockRuntimeManager mockRuntimeManager = new MockRuntimeManager(); private static IStoredSettings settings; @@ -513,7 +511,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" - + branch + "/" , link); + + branch + "/", link); } @Test @@ -676,58 +674,366 @@ public class RawServletTest @Test - public void getBranch() + public void getBranch_Repo() { + String branch = rawServlet.getBranch("test.git", "test.git/"); + + assertEquals("Branch was supposed to be empty as no branch was given.", "", branch); } @Test - public void getPath() + public void getBranch_PiNull() { + String branch = rawServlet.getBranch("test.git", null); + + assertEquals("Branch was supposed to be empty as path info is null.", "", branch); } + @Test - public void getBranch_Repo() + public void getBranch_PiEmpty() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn("/test.git/"); + String branch = rawServlet.getBranch("test.git", ""); - String branch = rawServlet.getBranch("test.git", request); + assertEquals("Branch was supposed to be empty as no path info exists.", "", branch); + } + + @Test + public void getBranch_LeadinRepo() + { + String branch = rawServlet.getBranch("test.git", "some/test.git/"); assertEquals("Branch was supposed to be empty as no branch was given.", "", branch); } @Test - public void getBranch_RepoNoTrailingSlash() + public void getBranch_ProjectRepo() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn("/test.git"); - - String branch = rawServlet.getBranch("test.git", request); + String branch = rawServlet.getBranch("smack/dab.git", "smack/dab.git/"); assertEquals("Branch was supposed to be empty as no branch was given.", "", branch); } @Test - public void getBranch_PiNull() + public void getBranch_RepoBranch() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn(null); + String branch = rawServlet.getBranch("test.git", "test.git/bee"); - String branch = rawServlet.getBranch("test.git", request); + assertEquals("bee", branch); + } - assertEquals("Branch was supposed to be empty as path info is null.", "", branch); + @Test + public void getBranch_LeadinRepoBranch() + { + String branch = rawServlet.getBranch("repo.git", "project/repo.git/bae"); + + assertEquals("bae", branch); + } + + @Test + public void getBranch_ProjectRepoBranch() + { + String branch = rawServlet.getBranch("test/r.git", "test/r.git/b"); + + assertEquals("b", branch); } + @Test + public void getBranch_LeadinProjectRepoBranch() + { + String branch = rawServlet.getBranch("test/r.git", "a/b/test/r.git/b"); + + assertEquals("b", branch); + } @Test - public void getBranch_PiEmpty() + public void getBranch_RepoBranchTrailingSlash() + { + String branch = rawServlet.getBranch("/test.git", "test.git/fixthis/"); + + assertEquals("fixthis", branch); + } + + @Test + public void getBranch_RepoBranchFile() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn(""); + String branch = rawServlet.getBranch("/bob.git", "bob.git/branch/file.txt"); - String branch = rawServlet.getBranch("test.git", request); + assertEquals("branch", branch); + } - assertEquals("Branch was supposed to be empty as no path info exists.", "", branch); + @Test + public void getBranch_RepoBranchFolderFile() + { + String branch = rawServlet.getBranch("/bill.git", "bill.git/flex/fold!laundr.y"); + + assertEquals("flex", branch); + } + + @Test + public void getBranch_RepoBranchFoldersTrailingSlash() + { + String branch = rawServlet.getBranch("bill.git", "bill.git/flex/fold!gold/"); + + assertEquals("flex", branch); + } + + @Test + public void getBranch_RepoBranchFoldersTrailingFsc() + { + String branch = rawServlet.getBranch("bill.git", "bill.git/flex/fold"+ FSC + "gold" + FSC); + + assertEquals("flex", branch); + } + + @Test + public void getBranch_LeadinProjectRepoBranchFoldersTrailingSlash() + { + String branch = rawServlet.getBranch("bam/bum.git", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm/"); + + assertEquals("klingeling", branch); + } + + @Test + public void getBranch_LeadinProjectRepoBranchFoldersTrailingFsc() + { + String branch = rawServlet.getBranch("bam/bum.git", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm" + FSC); + + assertEquals("klingeling", branch); + } + + @Test + public void getBranch_RepoCommitid() + { + String branch = rawServlet.getBranch("git.git", "git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89"); + + assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch); + } + + @Test + public void getBranch_ProjectRepoCommitidFolderTrailingSlash() + { + String branch = rawServlet.getBranch("git/git.git", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src/"); + + assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch); + } + + @Test + public void getBranch_ProjectRepoCommitidFolderTrailingFsc() + { + String branch = rawServlet.getBranch("git/git.git", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC); + + assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch); + } + + @Test + public void getBranch_ProjectSubRepoCommitidFolderFile() + { + String branch = rawServlet.getBranch("git/git.git", "Git implementations/git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC + "README.md"); + + assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch); + } + + @Test + public void getBranch_RepoBranchWithFsc() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase"); + + assertEquals("feature/rebase", branch); + } + + @Test + public void getBranch_RepoBranchWithTwoFsc() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase" + FSC + "onto"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_ProjectRepoBranchWithTwoFsc() + { + String branch = rawServlet.getBranch("Java/git/git.git", "Java/git/git.git/feature" + FSC + "rebase" + FSC + "onto"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_RepoBranchWithTwoFscTrailingSlash() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_ProjectRepoBranchWithTwoFscTrailingSlash() + { + String branch = rawServlet.getBranch("in Go/git.git", "in Go/git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_LeadinProjectRepoBranchWithTwoFscTrailingSlash() + { + String branch = rawServlet.getBranch("Go/git.git", "all the gits/Go/git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_RepoBranchWithFscFolder() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase/onto"); + + assertEquals("feature/rebase", branch); + } + + @Test + public void getBranch_RepoBranchWithFscFolderFile() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase/onto" + FSC + "head"); + + assertEquals("feature/rebase", branch); + } + + @Test + public void getBranch_RepoBranchWithFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "|"); + + String branch = rawServlet.getBranch("git.git", "git.git/some|feature"); + + assertEquals("some/feature", branch); + } + + @Test + public void getBranch_RepoBranchWithFsc_explicitFscSameAsDefault() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + + String branch = rawServlet.getBranch("git.git", "git.git/some" + FSC + "feature"); + + assertEquals("some/feature", branch); + } + + @Test + public void getBranch_RepoBranchWithFscFolders_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ":"); + + String branch = rawServlet.getBranch("git.git", "git.git/hotfix:1.2.3/src:main:java/"); + + assertEquals("hotfix/1.2.3", branch); + } + + @Test + public void getBranch_LeadindRepoBranchWithFscFolderFile_explicitFscSameAsDefault() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + + String branch = rawServlet.getBranch("git.git", "IBM/git.git/some" + FSC + "feature/some" + FSC + "folder" + FSC + "file.dot"); + + assertEquals("some/feature", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String branch = rawServlet.getBranch("git.git", "git.git/some" + FSC + "feature"); + + assertEquals("some" + FSC + "feature", branch); + } + + @Test + public void getBranch_RepoBranchWithDifferentFscFolderFileWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String branch = rawServlet.getBranch("git.git", "git.git/some;feature/path" + FSC + "to" + FSC + "file.txt"); + + assertEquals("some/feature", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ":"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to:start"); + + assertEquals("go" + FSC + "to/start", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect"); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingSlash_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+ prison/dont" + FSC + "collect/"); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect+"); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect" + FSC); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect+money.eur"); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_LeadinProjectRepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("games/Monopoly/git.git", "blah/games/Monopoly/git.git/go" + FSC + "to+prison/dont" + FSC + "collect+money.eur"); + + assertEquals("go" + FSC + "to/prison", branch); } @@ -740,46 +1046,381 @@ public class RawServletTest @Test public void getPath_Repo() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn("/test.git/"); - - String path = rawServlet.getPath("test.git", "", request); + String path = rawServlet.getPath("test.git", "", "test.git/"); assertEquals("Path was supposed to be empty as no path was given.", "", path); } @Test - public void getPath_RepoNoTrailingSlash() + public void getPath_PiNull() + { + String path = rawServlet.getPath("test.git", "", null); + + assertEquals("Path was supposed to be empty as path info is null.", "", path); + } + + + @Test + public void getPath_PiEmpty() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn("/test.git"); + String path = rawServlet.getPath("test.git", "", ""); - String path = rawServlet.getPath("test.git", "", request); + assertEquals("Path was supposed to be empty as no path info exists.", "", path); + } + + @Test + public void getPath_LeadinRepo() + { + String path = rawServlet.getPath("test.git", "", "some/test.git/"); assertEquals("Path was supposed to be empty as no path was given.", "", path); } @Test - public void getPath_PiNull() + public void getPath_ProjectRepo() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn(null); + String path = rawServlet.getPath("smack/dab.git", "", "smack/dab.git/"); - String path = rawServlet.getPath("test.git", "", request); + assertEquals("Path was supposed to be empty as no path was given.", "", path); + } - assertEquals("Path was supposed to be empty as path info is null.", "", path); + @Test + public void getPath_RepoBranch() + { + String path = rawServlet.getPath("test.git", "bee", "test.git/bee"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); } + @Test + public void getPath_LeadinRepoBranch() + { + String path = rawServlet.getPath("repo.git", "bae", "project/repo.git/bae"); + + assertEquals("Expected path to be empty since no path was present","" , path); + } @Test - public void getPath_PiEmpty() + public void getPath_ProjectRepoBranch() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn(""); + String path = rawServlet.getPath("test/r.git", "b", "test/r.git/b"); - String path = rawServlet.getPath("test.git", "", request); + assertEquals("Expected returned path to be empty since no path was present", "", path); + } - assertEquals("Path was supposed to be empty as no path info exists.", "", path); + @Test + public void getPath_LeadinProjectRepoBranch() + { + String path = rawServlet.getPath("test/r.git", "b", "a/b/test/r.git/b"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchTrailingSlash() + { + String path = rawServlet.getPath("test.git", "fixthis", "test.git/fixthis/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchFile() + { + String path = rawServlet.getPath("/bob.git", "branch", "bob.git/branch/file.txt"); + + assertEquals("file.txt", path); + } + + @Test + public void getPath_RepoBranchFolderFile() + { + String path = rawServlet.getPath("/bill.git", "flex", "bill.git/flex/fold" + FSC + "laundr.y"); + + assertEquals("fold/laundr.y", path); + } + + @Test + public void getPath_RepoBranchFoldersTrailingSlash() + { + String path = rawServlet.getPath("bill.git", "flex", "bill.git/flex/fold"+ FSC + "gold/"); + + assertEquals("fold/gold", path); + } + + @Test + public void getPath_RepoBranchFoldersTrailingFsc() + { + String path = rawServlet.getPath("bill.git", "flex", "bill.git/flex/fold"+ FSC + "gold" + FSC); + + assertEquals("fold/gold", path); + } + + @Test + public void getPath_LeadinProjectRepoBranchFoldersTrailingSlash() + { + String path = rawServlet.getPath("bam/bum.git", "klingeling", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm/"); + + assertEquals("dumm/di/dumm", path); + } + + @Test + public void getPath_LeadinProjectRepoBranchFoldersTrailingFsc() + { + String path = rawServlet.getPath("bam/bum.git", "klingeling", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm" + FSC); + + assertEquals("dumm/di/dumm", path); + } + + @Test + public void getPath_RepoCommitid() + { + String path = rawServlet.getPath("/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoCommitidNoTrailingSlash() + { + String path = rawServlet.getPath("/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_ProjectRepoCommitidFolderTrailingSlash() + { + String path = rawServlet.getPath("git/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src/"); + + assertEquals("src", path); + } + + @Test + public void getPath_ProjectRepoCommitidFolderTrailingFsc() + { + String path = rawServlet.getPath("git/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC); + + assertEquals("src", path); + } + + @Test + public void getPath_ProjectSubRepoCommitidFolderFile() + { + String path = rawServlet.getPath("git/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "Git implementations/git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC + "README.md"); + + assertEquals("src/README.md", path); + } + + @Test + public void getPath_RepoBranchWithFsc() + { + String path = rawServlet.getPath("git.git", "feature/rebase", "git.git/feature" + FSC + "rebase"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithTwoFsc() + { + String path = rawServlet.getPath("git.git", "feature/rebase/onto", "git.git/feature" + FSC + "rebase" + FSC + "onto"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_ProjectRepoBranchWithTwoFsc() + { + String path = rawServlet.getPath("Java/git/git.git", "feature/rebase/onto", "Java/git/git.git/feature" + FSC + "rebase" + FSC + "onto"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithTwoFscTrailingSlash() + { + String path = rawServlet.getPath("git.git", "feature/rebase/onto", "git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_ProjectRepoBranchWithTwoFscTrailingSlash() + { + String path = rawServlet.getPath("in Go/git.git", "feature/rebase/onto", "in Go/git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_LeadinProjectRepoBranchWithTwoFscTrailingSlash() + { + String path = rawServlet.getPath("Go/git.git", "feature/rebase/onto", "all the gits/Go/git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithFscFolder() + { + String path = rawServlet.getPath("git.git", "feature/rebase", "git.git/feature" + FSC + "rebase/onto"); + + assertEquals("onto", path); + } + + @Test + public void getPath_RepoBranchWithFscFolderFile() + { + String path = rawServlet.getPath("git.git", "feature/rebase", "git.git/feature" + FSC + "rebase/onto" + FSC + "head"); + + assertEquals("onto/head", path); + } + + @Test + public void getPath_RepoBranchWithFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "|"); + + String path = rawServlet.getPath("git.git", "some/feature", "git.git/some|feature"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithFsc_explicitFscSameAsDefault() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + + String path = rawServlet.getPath("git.git", "some/feature", "git.git/some" + FSC + "feature"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithFscFoldersTrailingSlash_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ":"); + + String path = rawServlet.getPath("git.git", "hotfix/1.2.3", "git.git/hotfix:1.2.3/src:main:java/"); + + assertEquals("src/main/java", path); } + @Test + public void getPath_LeadindRepoBranchWithFscFolderFile_explicitFscSameAsDefault() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + + String path = rawServlet.getPath("git.git", "some/feature", "IBM/git.git/some" + FSC + "feature/some" + FSC + "folder" + FSC + "file.dot"); + + assertEquals("some/folder/file.dot", path); + } + + @Test + public void getPath_RepoBranchWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String path = rawServlet.getPath("git.git", "some" + FSC + "feature", "git.git/some" + FSC + "feature"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + + @Test + public void getPath_RepoBranchWithDefaultFscTrailingSlash_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String path = rawServlet.getPath("git.git", "some" + FSC + "feature", "git.git/some" + FSC + "feature/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDifferentFscFolderFileWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String path = rawServlet.getPath("git.git", "some/feature", "git.git/some;feature/path" + FSC + "to" + FSC + "file.txt"); + + assertEquals("path" + FSC + "to" + FSC + "file.txt", path); + } + + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ":"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/start", "git.git/go" + FSC + "to:start"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect"); + + assertEquals("dont" + FSC + "collect", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingSlash_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect/"); + + assertEquals("dont" + FSC + "collect", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect+"); + + assertEquals("dont" + FSC + "collect", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect" + FSC); + + assertEquals("dont" + FSC + "collect" + FSC, path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/" + FSC + "dont" + FSC + "collect+money.eur"); + + assertEquals(FSC + "dont" + FSC + "collect/money.eur", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_LeadinProjectRepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("games/Monopoly/git.git", "go" + FSC + "to/prison", "blah/games/Monopoly/git.git/go" + FSC + "to+prison/dont" + FSC + "collect+money.eur"); + + assertEquals("dont" + FSC + "collect/money.eur", path); + } } -- cgit v1.2.3 From 1570199d3fc21c26b1c2a6603b9dc24317176b3f Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Mon, 9 Nov 2020 20:21:08 +0100 Subject: raw: Fix getPath with lead-ins or missing trailing slashes after the branch. --- src/main/java/com/gitblit/servlet/RawServlet.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/gitblit') diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index 8213850a..90e8ac74 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -165,13 +165,26 @@ public class RawServlet extends HttpServlet { { if (pathInfo == null || pathInfo.isEmpty() || pathInfo.equals("/")) return ""; String base = repository + "/" + branch; + + // 'repository/' or 'repository/branch' or 'repository/branch/' if (pathInfo.equals(base)) { return ""; } - String path = pathInfo.substring(pathInfo.indexOf(base) + base.length() + 1); + // I have no idea why 'indexOf(base)' is used, which assumes something could come before 'base' in + // the pathInfo string. But since it is here, we handle it until we completly refactor the paths used + // in Gitblit to something sensible. + // 'leadin/repository/' + // 'leadin/repository/branch' + int pathStart = pathInfo.indexOf(base) + base.length(); + // 'leadin/repository/branch/' + if (pathStart < pathInfo.length() && pathInfo.charAt(pathStart) == '/') pathStart++; + if (pathInfo.length() == pathStart) return ""; + String path = pathInfo.substring(pathStart); + // 'leadin/repository/branch/path/' if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } + // 'leadin/repository/branch/path' char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); return path.replace('!', '/').replace(c, '/'); } -- cgit v1.2.3 From 3212dc014c445425cc09f8d92065f1afb4e53065 Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Mon, 9 Nov 2020 20:27:31 +0100 Subject: raw: Fix getPath with trailing slash that was escaped While this may be an unlikely scenario, let's still prevent this. When a link was created for a path that ends in a trailing slash, that trailing slash would be replaced with the `forwardSlashCharacter`. But in getPath that final slash would be transformed back *after* the check to chop off trailing slashes. This is now switched so that such a trailing slash is also chopped off. --- src/main/java/com/gitblit/servlet/RawServlet.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/gitblit') diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index 90e8ac74..b0cba787 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -179,14 +179,18 @@ public class RawServlet extends HttpServlet { // 'leadin/repository/branch/' if (pathStart < pathInfo.length() && pathInfo.charAt(pathStart) == '/') pathStart++; if (pathInfo.length() == pathStart) return ""; + // 'leadin/repository/branch/path' String path = pathInfo.substring(pathStart); + + char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); + path = path.replace('!', '/').replace(c, '/'); + + // 'repository/branch/path/' // 'leadin/repository/branch/path/' if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } - // 'leadin/repository/branch/path' - char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); - return path.replace('!', '/').replace(c, '/'); + return path; } protected boolean renderIndex() { -- cgit v1.2.3 From 6876537c856dda897f081430bb11b394f8b291bb Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Mon, 9 Nov 2020 23:08:22 +0100 Subject: raw: Fix raw links to branches with a slash in their name When a branch has a slash in the name, the raw servlet was not able to find the path under that branch. This is due to the replacement of the forward slash character for URLs. It was not taken into account when comparing the branch name later. This fixes #1290 and its duplicates #1234 and #813. --- src/main/java/com/gitblit/servlet/RawServlet.java | 17 ++++++++---- .../java/com/gitblit/servlet/RawServletTest.java | 32 +++++++++++----------- 2 files changed, 27 insertions(+), 22 deletions(-) (limited to 'src/main/java/com/gitblit') diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index b0cba787..9161eb6a 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -69,6 +69,9 @@ import com.google.inject.Singleton; @Singleton public class RawServlet extends HttpServlet { + // Forward slash character + static final char FSC = '!'; + private static final long serialVersionUID = 1L; private transient Logger logger = LoggerFactory.getLogger(RawServlet.class); @@ -106,10 +109,9 @@ public class RawServlet extends HttpServlet { repository = repository.substring(1); } - char fsc = '!'; - char c = GitblitContext.getManager(IRuntimeManager.class).getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); - if (c != '/') { - fsc = c; + char fsc = GitblitContext.getManager(IRuntimeManager.class).getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); + if (fsc == '/') { + fsc = FSC; } if (branch != null) { branch = Repository.shortenRefName(branch).replace('/', fsc); @@ -164,7 +166,11 @@ public class RawServlet extends HttpServlet { String getPath(String repository, String branch, String pathInfo) { if (pathInfo == null || pathInfo.isEmpty() || pathInfo.equals("/")) return ""; - String base = repository + "/" + branch; + + // Make the branch look like in the URL, or else it won't match later in the `indexOf`. + char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); + char fsc = (c == '/') ? FSC : c; + String base = repository + "/" + Repository.shortenRefName(branch).replace('/', fsc); // 'repository/' or 'repository/branch' or 'repository/branch/' if (pathInfo.equals(base)) { @@ -182,7 +188,6 @@ public class RawServlet extends HttpServlet { // 'leadin/repository/branch/path' String path = pathInfo.substring(pathStart); - char c = runtimeManager.getSettings().getChar(Keys.web.forwardSlashCharacter, '/'); path = path.replace('!', '/').replace(c, '/'); // 'repository/branch/path/' diff --git a/src/test/java/com/gitblit/servlet/RawServletTest.java b/src/test/java/com/gitblit/servlet/RawServletTest.java index dac9896e..50587178 100644 --- a/src/test/java/com/gitblit/servlet/RawServletTest.java +++ b/src/test/java/com/gitblit/servlet/RawServletTest.java @@ -17,7 +17,7 @@ import static org.mockito.Mockito.mock; public class RawServletTest { - private static final String FSC = "!"; + private static final char FSC = RawServlet.FSC; private static MockRuntimeManager mockRuntimeManager = new MockRuntimeManager(); private static IStoredSettings settings; @@ -170,7 +170,7 @@ public class RawServletTest String link = RawServlet.asLink(baseUrl, repository, branch, path); assertNotNull(link); - assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch.replaceAll("/", FSC) + "/", link); + assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch.replace('/', FSC) + "/", link); } @Test @@ -185,7 +185,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/" - + branch.replaceAll("/", FSC) + "/", link); + + branch.replace('/', FSC) + "/", link); } @Test @@ -200,7 +200,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/" - + branch.replaceAll("/", FSC) + "/", link); + + branch.replace('/', FSC) + "/", link); } @Test @@ -215,7 +215,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/" - + branch.replaceAll("/", FSC) + "/", link); + + branch.replace('/', FSC) + "/", link); } @@ -245,7 +245,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/" - + branch + "/" + path.replaceAll("/", FSC), link); + + branch + "/" + path.replace('/', FSC), link); } @Test @@ -274,7 +274,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/" - + branch + "/" + path.replaceAll("/", FSC), link); + + branch + "/" + path.replace('/', FSC), link); } @@ -290,7 +290,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" - + branch.replaceAll("/", FSC) + "/" + path, link); + + branch.replace('/', FSC) + "/" + path, link); } @Test @@ -305,7 +305,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/" - + branch.replaceAll("/", FSC) + "/" + path.replaceAll("/", FSC), link); + + branch.replace('/', FSC) + "/" + path.replace('/', FSC), link); } @Test @@ -320,7 +320,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/" - + branch.replaceAll("/", FSC) + "/" + path, link); + + branch.replace('/', FSC) + "/" + path, link); } @Test @@ -335,7 +335,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/" - + branch.replaceAll("/", FSC) + "/" + path.replaceAll("/", FSC), link); + + branch.replace('/', FSC) + "/" + path.replace('/', FSC), link); } @Test @@ -393,7 +393,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" - + branch.replaceAll("/", FSC) + "/", link); + + branch.replace('/', FSC) + "/", link); } @Test @@ -423,7 +423,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/" - + branch.replaceAll("/", FSC) + "/" + path.replaceAll("/", FSC), link); + + branch.replace('/', FSC) + "/" + path.replace('/', FSC), link); } @Test @@ -541,7 +541,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" - + branch + "/" + path.replaceAll("/", FSC), link); + + branch + "/" + path.replace('/', FSC), link); } @Test @@ -1289,7 +1289,7 @@ public class RawServletTest @Test public void getPath_RepoBranchWithFsc_explicitFscSameAsDefault() { - settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + settings.overrideSetting(Keys.web.forwardSlashCharacter, String.valueOf(FSC)); String path = rawServlet.getPath("git.git", "some/feature", "git.git/some" + FSC + "feature"); @@ -1309,7 +1309,7 @@ public class RawServletTest @Test public void getPath_LeadindRepoBranchWithFscFolderFile_explicitFscSameAsDefault() { - settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + settings.overrideSetting(Keys.web.forwardSlashCharacter, String.valueOf(FSC)); String path = rawServlet.getPath("git.git", "some/feature", "IBM/git.git/some" + FSC + "feature/some" + FSC + "folder" + FSC + "file.dot"); -- cgit v1.2.3