From 259b02fbe82446d79fdd24d28b01923169eecbf1 Mon Sep 17 00:00:00 2001 From: Tomasz Sztejka Date: Wed, 17 Nov 2021 14:14:37 +0100 Subject: [PATCH 1/2] This commit fixes what was broken in commit https://github.com/gitblit/gitblit/commit/b23269acc0f460f583311c679d751925b8402563 due to #1358 issue --- .../java/com/gitblit/wicket/MarkupProcessor.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/gitblit/wicket/MarkupProcessor.java b/src/main/java/com/gitblit/wicket/MarkupProcessor.java index 7facc59e3..7c8d75563 100644 --- a/src/main/java/com/gitblit/wicket/MarkupProcessor.java +++ b/src/main/java/com/gitblit/wicket/MarkupProcessor.java @@ -360,6 +360,22 @@ public Rendering render(WikiLinkNode node) { @Override public Rendering render(ExpLinkNode node, String text) { + //Relative file-like MD links needs to be re-mapped to be relative to + //repository name so that they display correctly sub-folder files + //Absolute links must be left un-touched. + + //Note: The absolute lack of comments in ExpLinkNode is... well... + //I assume, that getRelativePath is handling "file like" links + //linke "/xx/tt" or "../somefolder". What needs to be captured it + //is a full URL link. The easiest is to ask java to parse URL + //and let it fail. Shame java.net.URL has no method to validate URL without + //throwing. + try{ + new java.net.URL(node.url); + //This is URL, fallback to superclass. + return super.render(node,text); + }catch(java.net.MalformedURLException ex){}; + //Now this is surely not an URL. String path = doc.getRelativePath(node.url); String url = getWicketUrl(DocPage.class, repositoryName, commitId, path); return new Rendering(url, text); From bdf3c7ac764be1582f9e14d37b282082854e7868 Mon Sep 17 00:00:00 2001 From: Florian Zschocke <2362065+flaix@users.noreply.github.com> Date: Thu, 18 Nov 2021 15:36:57 +0100 Subject: [PATCH 2/2] Adjust white-space style to rest of file --- .../com/gitblit/wicket/MarkupProcessor.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/MarkupProcessor.java b/src/main/java/com/gitblit/wicket/MarkupProcessor.java index 7c8d75563..300039bc4 100644 --- a/src/main/java/com/gitblit/wicket/MarkupProcessor.java +++ b/src/main/java/com/gitblit/wicket/MarkupProcessor.java @@ -360,22 +360,22 @@ public Rendering render(WikiLinkNode node) { @Override public Rendering render(ExpLinkNode node, String text) { - //Relative file-like MD links needs to be re-mapped to be relative to - //repository name so that they display correctly sub-folder files - //Absolute links must be left un-touched. + // Relative file-like MD links needs to be re-mapped to be relative to + // repository name so that they display correctly sub-folder files + // Absolute links must be left un-touched. - //Note: The absolute lack of comments in ExpLinkNode is... well... - //I assume, that getRelativePath is handling "file like" links - //linke "/xx/tt" or "../somefolder". What needs to be captured it - //is a full URL link. The easiest is to ask java to parse URL - //and let it fail. Shame java.net.URL has no method to validate URL without - //throwing. - try{ + // Note: The absolute lack of comments in ExpLinkNode is... well... + // I assume, that getRelativePath is handling "file like" links + // like "/xx/tt" or "../somefolder". What needs to be captured + // is a full URL link. The easiest is to ask java to parse URL + // and let it fail. Shame java.net.URL has no method to validate URL without + // throwing. + try { new java.net.URL(node.url); - //This is URL, fallback to superclass. + // This is URL, fallback to superclass. return super.render(node,text); - }catch(java.net.MalformedURLException ex){}; - //Now this is surely not an URL. + } catch (java.net.MalformedURLException ignored) {}; + // repository-relative link String path = doc.getRelativePath(node.url); String url = getWicketUrl(DocPage.class, repositoryName, commitId, path); return new Rendering(url, text);