diff --git a/build.sbt b/build.sbt index 198e35a..55e0631 100644 --- a/build.sbt +++ b/build.sbt @@ -41,7 +41,7 @@ "org.json4s" %% "json4s-jackson" % "3.5.2", "commons-io" % "commons-io" % "2.6", "io.github.gitbucket" % "solidbase" % "1.0.3", - "io.github.gitbucket" % "markedj" % "1.0.15", + "io.github.gitbucket" % "markedj" % "1.0.16", "org.apache.commons" % "commons-compress" % "1.18", "org.apache.commons" % "commons-email" % "1.5", "org.apache.httpcomponents" % "httpclient" % "4.5.6", diff --git a/src/main/scala/gitbucket/core/view/Markdown.scala b/src/main/scala/gitbucket/core/view/Markdown.scala index 40f68e0..9db2a95 100644 --- a/src/main/scala/gitbucket/core/view/Markdown.scala +++ b/src/main/scala/gitbucket/core/view/Markdown.scala @@ -169,22 +169,31 @@ private def fixUrl(url: String, branch: String, isImage: Boolean = false): String = { lazy val urlWithRawParam: String = url + (if (isImage && !url.endsWith("?raw=true")) "?raw=true" else "") - if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:") || url.startsWith("/")) { + if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:")) { url + } else if (url.startsWith("/")) { + context.baseUrl + url } else if (url.startsWith("#")) { ("#" + generateAnchorName(url.substring(1))) - } else if (!enableWikiLink) { - if (context.currentPath.contains("/blob/")) { - urlWithRawParam - } else if (context.currentPath.contains("/tree/")) { - val paths = context.currentPath.split("/") - val path = if (paths.length > 3) paths.drop(4).mkString("/") else branch - repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + path + "/" + urlWithRawParam - } else { - repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + branch + "/" + urlWithRawParam - } } else { - repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/wiki/_blob/" + url + // Relative path + if (!enableWikiLink) { + if (context.currentPath.contains("/blob/")) { + val paths = context.currentPath.split("/").dropRight(1) + val path = if (paths.length > 3) paths.drop(4).mkString("/") else branch + repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + path + "/" + urlWithRawParam + } else if (context.currentPath.contains("/tree/")) { + val paths = context.currentPath.split("/") + val path = if (paths.length > 3) paths.drop(4).mkString("/") else branch + repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + path + "/" + urlWithRawParam + } else { + repository.httpUrl + .replaceFirst("/git/", "/") + .stripSuffix(".git") + "/blob/" + branch + "/" + urlWithRawParam + } + } else { + repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/wiki/_blob/" + url + } } } diff --git a/src/main/scala/gitbucket/core/view/helpers.scala b/src/main/scala/gitbucket/core/view/helpers.scala index 067e330..b364b1e 100644 --- a/src/main/scala/gitbucket/core/view/helpers.scala +++ b/src/main/scala/gitbucket/core/view/helpers.scala @@ -218,14 +218,18 @@ .replaceAll( "\\[branch:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]", (m: Match) => - s"""${m - .group(3)}""" + s"""${StringUtil + .escapeHtml( + m.group(3) + )}""" ) .replaceAll( "\\[tag:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]", (m: Match) => - s"""${m - .group(3)}""" + s"""${StringUtil + .escapeHtml( + m.group(3) + )}""" ) .replaceAll("\\[user:([^\\s]+?)\\]", (m: Match) => user(m.group(1)).body) .replaceAll( @@ -237,8 +241,10 @@ .replaceAll( "\\[release:([^\\s]+?)/([^\\s]+?)/([^\\s]+?):(.+)\\]", (m: Match) => - s"""${m - .group(4)}""" + s"""${StringUtil + .escapeHtml( + m.group(4) + )}""" ) ) diff --git a/src/main/twirl/gitbucket/core/account/main.scala.html b/src/main/twirl/gitbucket/core/account/main.scala.html index 4c2ebc0..793283c 100644 --- a/src/main/twirl/gitbucket/core/account/main.scala.html +++ b/src/main/twirl/gitbucket/core/account/main.scala.html @@ -12,21 +12,26 @@
@description
} - @if(account.url.isDefined){ + @account.url.map { url => } @if(context.settings.showMailAddress){ - @extraMailAddresses.map{ mail => + @extraMailAddresses.map { mail => } } diff --git a/src/test/scala/gitbucket/core/view/MarkdownSpec.scala b/src/test/scala/gitbucket/core/view/MarkdownSpec.scala index 25e4de6..b77ffb4 100644 --- a/src/test/scala/gitbucket/core/view/MarkdownSpec.scala +++ b/src/test/scala/gitbucket/core/view/MarkdownSpec.scala @@ -154,7 +154,7 @@ )(context) assert( - html == """""" + html == """""" ) } }