Add property to configure path separator in URLs for a gitweb service
In URLs to a gitweb service, Gerrit by default will escape slashes in project and branch names replacing them with the corresponding hexa- decimal encoding. Some web servers, such as Tomcat, reject hexadecimal encoded slashes in the URL. The gitweb service GitBlit, allows to configure an alternative path separator character (e.g. '*'). This change introduces the property "gitweb.pathSeparator", which allows to configure a path separator in Gerrit matching the path separator used by the gitweb service. Change-Id: I0c67e6264abfa156e4c513e1fad17dac141fa7d3 Signed-off-by: Adrian Goerler <adrian.goerler@sap.com>
This commit is contained in:
@@ -71,6 +71,10 @@ public class GitWebType {
|
||||
/** ParamertizedString for file history view url. */
|
||||
private String fileHistory;
|
||||
|
||||
/** Character to substitute the standard path separator '/' in branch and
|
||||
* project names */
|
||||
private char pathSeparator = '/';
|
||||
|
||||
/** Private default constructor for gson. */
|
||||
protected GitWebType() {
|
||||
}
|
||||
@@ -174,4 +178,27 @@ public class GitWebType {
|
||||
fileHistory = pattern;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the standard path separator ('/') in a branch name or project
|
||||
* name with a custom path separator configured by the property
|
||||
* gitweb.pathSeparator.
|
||||
* @param urlSegment The branch or project to replace the path separator in
|
||||
* @return the urlSegment with the standard path separator replaced by the
|
||||
* custom path separator
|
||||
*/
|
||||
public String replacePathSeparator(String urlSegment) {
|
||||
if ('/' != pathSeparator) {
|
||||
return urlSegment.replace('/', pathSeparator);
|
||||
}
|
||||
return urlSegment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the custom path separator
|
||||
* @param separator The custom path separator
|
||||
*/
|
||||
public void setPathSeparator(char separator) {
|
||||
this.pathSeparator = separator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ public class GitwebLink {
|
||||
ParameterizedString pattern = new ParameterizedString(type.getRevision());
|
||||
|
||||
final Map<String, String> p = new HashMap<String, String>();
|
||||
p.put("project", URL.encodeQueryString(project.get()));
|
||||
p.put("commit", URL.encodeQueryString(ps.getRevision().get()));
|
||||
p.put("project", encode(project.get()));
|
||||
p.put("commit", encode(ps.getRevision().get()));
|
||||
return baseUrl + pattern.replace(p);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class GitwebLink {
|
||||
ParameterizedString pattern = new ParameterizedString(type.getProject());
|
||||
|
||||
final Map<String, String> p = new HashMap<String, String>();
|
||||
p.put("project", URL.encodeQueryString(project.get()));
|
||||
p.put("project", encode(project.get()));
|
||||
return baseUrl + pattern.replace(p);
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ public class GitwebLink {
|
||||
ParameterizedString pattern = new ParameterizedString(type.getBranch());
|
||||
|
||||
final Map<String, String> p = new HashMap<String, String>();
|
||||
p.put("project", URL.encodeQueryString(branch.getParentKey().get()));
|
||||
p.put("branch", URL.encodeQueryString(branch.get()));
|
||||
p.put("project", encode(branch.getParentKey().get()));
|
||||
p.put("branch", encode(branch.get()));
|
||||
return baseUrl + pattern.replace(p);
|
||||
}
|
||||
|
||||
@@ -70,9 +70,13 @@ public class GitwebLink {
|
||||
ParameterizedString pattern = new ParameterizedString(type.getFileHistory());
|
||||
|
||||
final Map<String, String> p = new HashMap<String, String>();
|
||||
p.put("project", URL.encodeQueryString(branch.getParentKey().get()));
|
||||
p.put("branch", URL.encodeQueryString(branch.get()));
|
||||
p.put("file", URL.encodeQueryString(file));
|
||||
p.put("project", encode(branch.getParentKey().get()));
|
||||
p.put("branch", encode(branch.get()));
|
||||
p.put("file", encode(file));
|
||||
return baseUrl + pattern.replace(p);
|
||||
}
|
||||
|
||||
private String encode(String segment) {
|
||||
return URL.encodeQueryString(type.replacePathSeparator(segment));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user