Do not encode file path in URL If the file path is encoded relative links cannot be resolved, e.g. a file 'foo/bar.md' which contains a relative link to 'foo/other.md' as '[other](other.md)' would be resolved to 'other.md' instead of 'foo/other.md' (because '/' in the URL of 'foo/bar.md' is encoded as '%2F'). Change-Id: I6eecdec621caa88893f98f5b1330138f861b1f8c Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java index 28d30f7..2b981cb 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java +++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
@@ -370,7 +370,7 @@ redirectUrl.append(key.revision); redirectUrl.append("/"); } - redirectUrl.append(IdString.fromDecoded(cfg.getIndexFile()).encoded()); + redirectUrl.append(cfg.getIndexFile()); return redirectUrl.toString(); } @@ -406,13 +406,13 @@ i = rest.indexOf('/'); if (i != -1 && i != path.length() - 1) { revision = IdString.fromUrl(rest.substring(0, i)).get(); - file = IdString.fromUrl(rest.substring(i + 1)).get(); + file = rest.substring(i + 1); } else { revision = IdString.fromUrl(rest).get(); } } } else { - file = IdString.fromUrl(rest).get(); + file = rest; } } else {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocWebLink.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocWebLink.java index 05a0e7d..1d7cf4e 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocWebLink.java +++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocWebLink.java
@@ -136,7 +136,7 @@ url.append(Url.encode(revision)); } url.append("/"); - url.append(Url.encode(fileName)); + url.append(fileName); return url.toString(); } else { return null;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocApi.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocApi.java index e8de4ab..e7cde1c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocApi.java +++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocApi.java
@@ -36,7 +36,7 @@ url.append(URL.encodeQueryString(revision)); } url.append("/"); - url.append(URL.encodeQueryString(path)); + url.append(path); return url.toString(); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocScreen.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocScreen.java index f60e140..40ea088 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocScreen.java +++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocScreen.java
@@ -30,7 +30,7 @@ public void onLoad(Screen screen) { String projectName = URL.decode(screen.getToken(1)); String revision = URL.decode(screen.getToken(2)); - String path = URL.decode(screen.getToken(3)); + String path = screen.getToken(3); screen.show(new XDocScreen(projectName, revision, path)); screen.setWindowTitle(FileInfo.getFileName(path)); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocSideBySideDiffScreen.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocSideBySideDiffScreen.java index d96c6ab..5f1930c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocSideBySideDiffScreen.java +++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocSideBySideDiffScreen.java
@@ -28,7 +28,7 @@ public void onLoad(Screen screen) { String change = URL.decode(screen.getToken(1)); String patchSet = URL.decode(screen.getToken(2)); - String path = URL.decode(screen.getToken(4)); + String path = screen.getToken(4); screen.show(new XDocSideBySideDiffScreen(change, patchSet, path)); screen.setWindowTitle(FileInfo.getFileName(path)); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocUnifiedDiffScreen.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocUnifiedDiffScreen.java index f97f527..42df4d0 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocUnifiedDiffScreen.java +++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocUnifiedDiffScreen.java
@@ -28,7 +28,7 @@ public void onLoad(Screen screen) { String change = URL.decode(screen.getToken(1)); String patchSet = URL.decode(screen.getToken(2)); - String path = URL.decode(screen.getToken(4)); + String path = screen.getToken(4); screen.show(new XDocUnifiedDiffScreen(change, patchSet, path)); screen.setWindowTitle(FileInfo.getFileName(path)); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocsPlugin.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocsPlugin.java index 3d62ac3..4d09480 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocsPlugin.java +++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/client/XDocsPlugin.java
@@ -24,13 +24,13 @@ @Override public void onPluginLoad() { - Plugin.get().screenRegex("project/(.*)/rev/(.*)/(.*)", + Plugin.get().screenRegex("project/([^/]*)/rev/([^/]*)/(.*)", new XDocScreen.Factory()); - Plugin.get().screenRegex("project/(.*)/(.*)", + Plugin.get().screenRegex("project/([^/]*)/(.*)", new XDocScreen.HeadFactory()); - Plugin.get().screenRegex("c/(.*)/([0-9]+(\\.{2}[0-9]+)?)/(.*),unified", + Plugin.get().screenRegex("c/([^/]*)/([0-9]+(\\.{2}[0-9]+)?)/(.*),unified", new XDocUnifiedDiffScreen.Factory()); - Plugin.get().screenRegex("c/(.*)/([0-9]+(\\.{2}[0-9]+)?)/(.*)", + Plugin.get().screenRegex("c/([^/]*)/([0-9]+(\\.{2}[0-9]+)?)/(.*)", new XDocSideBySideDiffScreen.Factory()); }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/ImageFormatter.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/ImageFormatter.java index 3bdc8af..901f900 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/ImageFormatter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/ImageFormatter.java
@@ -57,7 +57,7 @@ url.append(Url.encode(revision)); } url.append("/"); - url.append(Url.encode(path)); + url.append(path); return url.toString(); } }
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md index 7337f64..f59aa46 100644 --- a/src/main/resources/Documentation/about.md +++ b/src/main/resources/Documentation/about.md
@@ -2,15 +2,15 @@ If projects contain documentation, e.g. as Markdown files, the plugin automatically serves the generated HTML under -`/@PLUGIN@/project/<project-name>/<file-name>`. The project name and -the file name must be URL encoded. +`/@PLUGIN@/project/<project-name>/<file-name>`. The project name must +be URL encoded. The file is served from the branch/commit to which `HEAD` points unless a revision is specified in the URL as `/@PLUGIN@/project/<project-name>/rev/<rev>/<file-name>`. ``` - /@PLUGIN@/project/external%2Fopenssl/rev/stable-1.3/docs%2Ffaq.md + /@PLUGIN@/project/external%2Fopenssl/rev/stable-1.3/docs/faq.md ``` `rev` can be any ref or commit that is visible to the calling user. @@ -22,7 +22,7 @@ unformatted text. ``` - /@PLUGIN@/project/external%2Fopenssl/rev/stable-1.3/docs%2Ffaq.md?raw + /@PLUGIN@/project/external%2Fopenssl/rev/stable-1.3/docs/faq.md?raw ``` The `raw` parameter cannot be used for binary files.
diff --git a/src/main/resources/Documentation/user.md b/src/main/resources/Documentation/user.md index 32473e6..5c47321 100644 --- a/src/main/resources/Documentation/user.md +++ b/src/main/resources/Documentation/user.md
@@ -41,8 +41,7 @@ The URL scheme of the plugin allows to access the HTML of all project documentation files in the project from any revision (branch or -commit). The project name, the revision and the file name must be URL -encoded. +commit). The project name and the revision must be URL encoded. ``` /@PLUGIN@/project/<project>/rev/<revision>/<file> @@ -51,7 +50,7 @@ E.g.: ``` - /@PLUGIN@/project/dev%2Ftools%2Fcode-checks/rev/stable-1.3/docs%2Ffaq.md + /@PLUGIN@/project/dev%2Ftools%2Fcode-checks/rev/stable-1.3/docs/faq.md ``` A project documentation file can contain links to other project