]> source.dussan.org Git - gitblit.git/commitdiff
raw: Refactor RawServlet:getBranch and :getPath parameters
authorFlorian Zschocke <f.zschocke+git@gmail.com>
Sun, 8 Nov 2020 16:19:35 +0000 (17:19 +0100)
committerFlorian Zschocke <f.zschocke+git@gmail.com>
Mon, 9 Nov 2020 22:19:53 +0000 (23:19 +0100)
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.

src/main/java/com/gitblit/servlet/PagesServlet.java
src/main/java/com/gitblit/servlet/RawServlet.java
src/test/java/com/gitblit/servlet/RawServletTest.java

index 1473e966731687869e30341cfda19acb52a7e595..a76a50b5c871681a1d9619b65211d91e294c5d6e 100644 (file)
@@ -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 "";
                }
index 211d847d132eca543645483cd645925341620944..8213850a29eede59103a1e85c1e34246f88eb5cb 100644 (file)
@@ -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);
index 1deacf7e8acb2cbc2a7b2e05ddc48dd4fc0a2935..dac9896eadfdede92e0f3bd27d2de7824dc4cbd0 100644 (file)
@@ -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);
+    }
 }