@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);
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);
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)) {
// '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/'
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;
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
assertNotNull(link);
assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", FSC) + "/", link);
+ + branch.replace('/', FSC) + "/", link);
}
@Test
assertNotNull(link);
assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
- + branch.replaceAll("/", FSC) + "/", link);
+ + branch.replace('/', FSC) + "/", link);
}
@Test
assertNotNull(link);
assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
- + branch.replaceAll("/", FSC) + "/", link);
+ + branch.replace('/', FSC) + "/", link);
}
assertNotNull(link);
assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
- + branch + "/" + path.replaceAll("/", FSC), link);
+ + branch + "/" + path.replace('/', FSC), link);
}
@Test
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);
}
assertNotNull(link);
assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", FSC) + "/" + path, link);
+ + branch.replace('/', FSC) + "/" + path, link);
}
@Test
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
assertNotNull(link);
assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
- + branch.replaceAll("/", FSC) + "/" + path, link);
+ + branch.replace('/', FSC) + "/" + path, link);
}
@Test
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
assertNotNull(link);
assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", FSC) + "/", link);
+ + branch.replace('/', FSC) + "/", link);
}
@Test
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
assertNotNull(link);
assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + "/" + path.replaceAll("/", FSC), link);
+ + branch + "/" + path.replace('/', FSC), link);
}
@Test
@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");
@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");