Skip to content

Commit

Permalink
Fix retrieval of path from URL
Browse files Browse the repository at this point in the history
The XDocServlet needs the endcoded URL path, but it used
HttpServletRequest.getPathInfo() to retrieve it which returns the
decoded path. So far this worked because there was a bug in Guice [1]
that made HttpServletRequest.getPathInfo() return the encoded path.
Now this bug was fixed in Guice and Gerrit was updated to use the new
Guice version. Hence the XDocServlet started to fail and needs to be
adapted.

[1] google/guice#745

Change-Id: Ia14908ed0970e9e5eda0569e345c14fb5f255709
Signed-off-by: Edwin Kempin <ekempin@google.com>
(cherry picked from commit 10c5263)
  • Loading branch information
EdwinKempin authored and sschuberth committed Dec 3, 2015
1 parent 70cdbbc commit a1c225e
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.hash.Hashing;
import com.google.common.net.HttpHeaders;
import com.google.gerrit.common.data.PatchScript.FileMode;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
Expand Down Expand Up @@ -76,6 +77,7 @@ public class XDocServlet extends HttpServlet {

public static final String PATH_PREFIX = "/project/";

private final String pluginName;
private final Provider<ReviewDb> db;
private final ProjectControl.Factory projectControlFactory;
private final ProjectCache projectCache;
Expand All @@ -88,6 +90,7 @@ public class XDocServlet extends HttpServlet {

@Inject
XDocServlet(
@PluginName String pluginName,
Provider<ReviewDb> db,
ProjectControl.Factory projectControlFactory,
ProjectCache projectCache,
Expand All @@ -97,6 +100,7 @@ public class XDocServlet extends HttpServlet {
FileTypeRegistry fileTypeRegistry,
XDocProjectConfig.Factory cfgFactory,
Formatters formatters) {
this.pluginName = pluginName;
this.db = db;
this.projectControlFactory = projectControlFactory;
this.projectCache = projectCache;
Expand All @@ -114,7 +118,7 @@ public void service(HttpServletRequest req, HttpServletResponse res)
try {
validateRequestMethod(req);

ResourceKey key = ResourceKey.fromPath(req.getPathInfo());
ResourceKey key = ResourceKey.fromPath(getEncodedPath(req));
ProjectState state = getProject(key);
XDocProjectConfig cfg = cfgFactory.create(state);

Expand Down Expand Up @@ -193,6 +197,15 @@ public void service(HttpServletRequest req, HttpServletResponse res)
}
}

private String getEncodedPath(HttpServletRequest req) {
String path = req.getRequestURI();
String prefix = "/plugins/" + pluginName;
if (path.startsWith(prefix)) {
path = path.substring(prefix.length());
}
return path;
}

private Resource getImageResource(Repository repo, DiffMode diffMode,
ObjectId revId, ObjectId revIdB, String file) {
ObjectId id = diffMode == DiffMode.NO_DIFF || diffMode == DiffMode.SIDEBYSIDE_A
Expand Down

0 comments on commit a1c225e

Please sign in to comment.