mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
Fixed url generated by pull request/compare button
The `:` character was getting escaped leading to an ugly url. This is different from the urls generated when editing the branches in a pull request. In that case the url did not have `:` escaped.
This commit is contained in:
@@ -160,6 +160,12 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
|||||||
*/
|
*/
|
||||||
def encodeRefName(value: String): String = StringUtil.urlEncode(value).replace("%2F", "/")
|
def encodeRefName(value: String): String = StringUtil.urlEncode(value).replace("%2F", "/")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Url encode except '/' and ':'
|
||||||
|
*/
|
||||||
|
def encodeCompareBranch(value: String) =
|
||||||
|
StringUtil.urlEncode(value).replace("%2F", "/").replace("%3A", ":")
|
||||||
|
|
||||||
def urlEncode(value: String): String = StringUtil.urlEncode(value)
|
def urlEncode(value: String): String = StringUtil.urlEncode(value)
|
||||||
|
|
||||||
def urlEncode(value: Option[String]): String = value.map(urlEncode).getOrElse("")
|
def urlEncode(value: Option[String]): String = value.map(urlEncode).getOrElse("")
|
||||||
|
|||||||
@@ -30,9 +30,9 @@
|
|||||||
}
|
}
|
||||||
}.getOrElse{
|
}.getOrElse{
|
||||||
@if(context.loginAccount.isDefined){
|
@if(context.loginAccount.isDefined){
|
||||||
<a href="@url(repository)/compare/@{encodeRefName(repositoryDefaultCompareOrigin(repository.repository))}...@{encodeRefName(branch.name)}?expand=1" class="btn btn-small">New Pull Request</a>
|
<a href="@url(repository)/compare/@{encodeCompareBranch(repositoryDefaultCompareOrigin(repository.repository))}...@{encodeCompareBranch(branch.name)}?expand=1" class="btn btn-small">New Pull Request</a>
|
||||||
}else{
|
}else{
|
||||||
<a href="@url(repository)/compare/@{encodeRefName(repositoryDefaultCompareOrigin(repository.repository))}...@{encodeRefName(branch.name)}" class="btn btn-small">Compare</a>
|
<a href="@url(repository)/compare/@{encodeCompareBranch(repositoryDefaultCompareOrigin(repository.repository))}...@{encodeCompareBranch(branch.name)}" class="btn btn-small">Compare</a>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@if(hasWritePermission){
|
@if(hasWritePermission){
|
||||||
|
|||||||
@@ -34,4 +34,18 @@ class HelpersSpec extends Specification {
|
|||||||
helpers.repositoryDefaultCompareOrigin(repo) mustEqual "parent-user:some-branch"
|
helpers.repositoryDefaultCompareOrigin(repo) mustEqual "parent-user:some-branch"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"encodeCompareBranch" should {
|
||||||
|
"not uri encode /" in {
|
||||||
|
helpers.encodeCompareBranch("foo/bar#baz") mustEqual "foo/bar%23baz"
|
||||||
|
}
|
||||||
|
|
||||||
|
"not uri encode :" in {
|
||||||
|
helpers.encodeCompareBranch("foo:bar#baz") mustEqual "foo:bar%23baz"
|
||||||
|
}
|
||||||
|
|
||||||
|
"uri encode special characters" in {
|
||||||
|
helpers.encodeCompareBranch("!#$&'()+,;=?@[]") mustEqual "%21%23%24%26%27%28%29%2B%2C%3B%3D%3F%40%5B%5D"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user