mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-01 19:15:59 +01:00
Merge pull request #1741 from gitbucket/encode-url-path
Encode file paths in URL
This commit is contained in:
@@ -7,11 +7,11 @@
|
||||
isBlame: Boolean,
|
||||
isLfsFile: Boolean)(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.view.helpers
|
||||
@gitbucket.core.html.main(s"${(repository.name :: pathList).mkString("/")} at ${helpers.encodeRefName(branch)} - ${repository.owner}/${repository.name}", Some(repository)) {
|
||||
@gitbucket.core.html.main(s"${(repository.name :: pathList).mkString("/")} at ${branch} - ${repository.owner}/${repository.name}", Some(repository)) {
|
||||
@gitbucket.core.html.menu("files", repository){
|
||||
<div class="head">
|
||||
<div class="pull-right hide-if-blame"><div class="btn-group">
|
||||
<a href="@helpers.url(repository)/blob/@latestCommit.id/@pathList.mkString("/")" data-hotkey="y" style="display: none;">Transfer to URL with SHA</a>
|
||||
<a href="@helpers.url(repository)/blob/@helpers.encodeRefName((latestCommit.id :: pathList).mkString("/"))" data-hotkey="y" style="display: none;">Transfer to URL with SHA</a>
|
||||
<a href="@helpers.url(repository)/find/@helpers.encodeRefName(branch)" class="btn btn-sm btn-default" data-hotkey="t">Find file</a>
|
||||
</div></div>
|
||||
<div class="line-age-legend">
|
||||
@@ -31,13 +31,9 @@
|
||||
<span>Older</span>
|
||||
</div>
|
||||
<div id="branchCtrlWrapper" style="display:inline;">
|
||||
@gitbucket.core.helper.html.branchcontrol(
|
||||
branch,
|
||||
repository,
|
||||
hasWritePermission
|
||||
){
|
||||
@gitbucket.core.helper.html.branchcontrol(branch, repository, hasWritePermission){
|
||||
@repository.branchList.map { x =>
|
||||
<li><a href="@helpers.url(repository)/blob/@helpers.encodeRefName(x)/@pathList.mkString("/")">@gitbucket.core.helper.html.checkicon(x == branch) @x</a></li>
|
||||
<li><a href="@helpers.url(repository)/blob/@helpers.encodeRefName((x :: pathList).mkString("/"))">@gitbucket.core.helper.html.checkicon(x == branch) @x</a></li>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
@@ -46,7 +42,7 @@
|
||||
@if(i == pathList.length - 1){
|
||||
@section
|
||||
} else {
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)/@pathList.take(i + 1).mkString("/")">@section</a> /
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName((branch :: pathList.take(i + 1)).mkString("/"))">@section</a> /
|
||||
}
|
||||
}
|
||||
@if(isLfsFile){
|
||||
@@ -61,15 +57,16 @@
|
||||
<a href="@helpers.url(repository)/commit/@latestCommit.id" class="commit-message">@helpers.link(latestCommit.summary, repository)</a>
|
||||
<div class="btn-group pull-right">
|
||||
@if(hasWritePermission && content.viewType == "text" && repository.branchList.contains(branch)){
|
||||
<a class="btn btn-sm btn-default" href="@helpers.url(repository)/edit/@helpers.encodeRefName(branch)/@pathList.mkString("/")">Edit</a>
|
||||
<a class="btn btn-sm btn-default" href="@helpers.url(repository)/edit/@helpers.encodeRefName((branch :: pathList).mkString("/"))">Edit</a>
|
||||
}
|
||||
<a class="btn btn-sm btn-default" href="@helpers.url(repository)/raw/@latestCommit.id/@pathList.mkString("/")">Raw</a>
|
||||
<a class="btn btn-sm btn-default" href="@helpers.url(repository)/raw/@latestCommit.id/@helpers.encodeRefName(pathList.mkString("/"))">Raw</a>
|
||||
@if(content.viewType == "text"){
|
||||
<a class="btn btn-sm btn-default blame-action" href="@helpers.url(repository)/blame/@latestCommit.id/@pathList.mkString("/")" data-url="@helpers.url(repository)/get-blame/@latestCommit.id/@pathList.mkString("/")" data-repository="@helpers.url(repository)">Blame</a>
|
||||
<a class="btn btn-sm btn-default blame-action" href="@helpers.url(repository)/blame/@latestCommit.id/@helpers.encodeRefName(pathList.mkString("/"))"
|
||||
data-url="@helpers.url(repository)/get-blame/@helpers.encodeRefName((latestCommit.id :: pathList).mkString("/"))" data-repository="@helpers.url(repository)">Blame</a>
|
||||
}
|
||||
<a class="btn btn-sm btn-default" href="@helpers.url(repository)/commits/@helpers.encodeRefName(branch)/@pathList.mkString("/")">History</a>
|
||||
<a class="btn btn-sm btn-default" href="@helpers.url(repository)/commits/@helpers.encodeRefName((branch :: pathList).mkString("/"))">History</a>
|
||||
@if(hasWritePermission && repository.branchList.contains(branch)){
|
||||
<a class="btn btn-sm btn-danger" href="@helpers.url(repository)/remove/@helpers.encodeRefName(branch)/@pathList.mkString("/")">Delete</a>
|
||||
<a class="btn btn-sm btn-danger" href="@helpers.url(repository)/remove/@helpers.encodeRefName((branch :: pathList).mkString("/"))">Delete</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -88,12 +85,12 @@
|
||||
}
|
||||
@if(content.viewType == "image"){
|
||||
<div class="box-content-bottom">
|
||||
<img src="@helpers.url(repository)/raw/@helpers.encodeRefName(branch)/@pathList.mkString("/")"/>
|
||||
<img src="@helpers.url(repository)/raw/@helpers.encodeRefName((branch :: pathList).mkString("/"))"/>
|
||||
</div>
|
||||
}
|
||||
@if(content.viewType == "large" || content.viewType == "binary"){
|
||||
<div class="box-content-bottom" style="text-align: center; padding-top: 20px; padding-bottom: 20px;">
|
||||
<a href="@helpers.url(repository)/raw/@helpers.encodeRefName(branch)/@pathList.mkString("/")">View Raw</a><br>
|
||||
<a href="@helpers.url(repository)/raw/@helpers.encodeRefName((branch :: pathList).mkString("/"))">View Raw</a><br>
|
||||
<br>
|
||||
(Sorry about that, but we can't show files that are this big right now)
|
||||
</div>
|
||||
@@ -133,7 +130,7 @@ $(window).load(function(){
|
||||
}
|
||||
var line = pos[i].id.replace(/^L/,'');
|
||||
var hash = location.hash;
|
||||
var commitUrl = '@helpers.url(repository)/blob/@latestCommit.id/@pathList.mkString("/")';
|
||||
var commitUrl = '@helpers.url(repository)/blob/@helpers.encodeRefName((latestCommit.id :: pathList).mkString("/"))';
|
||||
if(e.shiftKey == true && hash.match(/#L\d+(-L\d+)?/)){
|
||||
var lines = hash.split('-');
|
||||
window.history.pushState('', '', commitUrl + lines[0] + '-L' + line);
|
||||
@@ -170,7 +167,7 @@ $(window).load(function(){
|
||||
updateSourceLineNum();
|
||||
return;
|
||||
}
|
||||
$(document.body).toggleClass('no-box-shadow', document.body.style.boxShadow===undefined);
|
||||
$(document.body).toggleClass('no-box-shadow', document.body.style.boxShadow === undefined);
|
||||
$('.blame-action').addClass("active");
|
||||
var base = $('<div class="blame">').css({height: pre.height()}).prependTo(pre.parents("div.box-content-bottom"));
|
||||
base.parent().addClass("blame-container");
|
||||
|
||||
@@ -12,11 +12,7 @@
|
||||
@gitbucket.core.html.menu("files", repository){
|
||||
<div class="head">
|
||||
@if(pathList.isEmpty){
|
||||
@gitbucket.core.helper.html.branchcontrol(
|
||||
branch,
|
||||
repository,
|
||||
hasWritePermission
|
||||
){
|
||||
@gitbucket.core.helper.html.branchcontrol(branch, repository, hasWritePermission){
|
||||
@repository.branchList.map { x =>
|
||||
<li><a href="@helpers.url(repository)/commits/@helpers.encodeRefName(x)">@gitbucket.core.helper.html.checkicon(x == branch) @x</a></li>
|
||||
}
|
||||
@@ -29,7 +25,7 @@
|
||||
@if(i == pathList.length - 1){
|
||||
<span class="strong">@section</span>
|
||||
} else {
|
||||
<a class="strong" href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)/@pathList.take(i + 1).mkString("/")">@section</a> /
|
||||
<a class="strong" href="@helpers.url(repository)/tree/@helpers.encodeRefName((branch :: pathList.take(i + 1)).mkString("/"))">@section</a> /
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<div class="head">
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)">@repository.name</a> /
|
||||
@pathList.zipWithIndex.map { case (section, i) =>
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)/@pathList.take(i + 1).mkString("/")">@section</a> /
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName((branch :: pathList.take(i + 1)).mkString("/"))">@section</a> /
|
||||
}
|
||||
@fileName
|
||||
<input type="hidden" name="fileName" id="fileName" value="@fileName"/>
|
||||
@@ -25,7 +25,7 @@
|
||||
<th style="font-weight: normal;" class="box-header">
|
||||
<span class="monospace">@fileName</span>
|
||||
<div class="pull-right align-right">
|
||||
<a href="@helpers.url(repository)/blob/@branch/@{(pathList ::: List(fileName)).mkString("/")}" class="btn btn-default btn-sm">View</a>
|
||||
<a href="@helpers.url(repository)/blob/@helpers.encodeRefName((branch :: pathList ::: List(fileName)).mkString("/"))" class="btn btn-default btn-sm">View</a>
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
@@ -46,7 +46,7 @@
|
||||
<input type="text" name="message" class="form-control"/>
|
||||
</div>
|
||||
<div style="text-align: right;">
|
||||
<a href="@helpers.url(repository)/blob/@helpers.encodeRefName(branch)/@pathList.mkString("/")" class="btn btn-danger">Cancel</a>
|
||||
<a href="@helpers.url(repository)/blob/@helpers.encodeRefName((branch :: pathList).mkString("/"))" class="btn btn-danger">Cancel</a>
|
||||
<input type="submit" id="commitButton" class="btn btn-success" value="Commit changes"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<div class="head">
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)">@repository.name</a> /
|
||||
@pathList.zipWithIndex.map { case (section, i) =>
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)/@pathList.take(i + 1).mkString("/")">@section</a> /
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName((branch :: pathList.take(i + 1)).mkString("/"))">@section</a> /
|
||||
}
|
||||
<input type="text" name="newFileName" id="newFileName" class="form-control" placeholder="Name your file..." value="@fileName"/>
|
||||
<input type="hidden" name="oldFileName" id="oldFileName" value="@fileName"/>
|
||||
@@ -58,9 +58,9 @@
|
||||
</div>
|
||||
<div style="text-align: right;">
|
||||
@if(fileName.isEmpty){
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)/@{pathList.mkString("/")}" class="btn btn-danger">Cancel</a>
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName((branch :: pathList).mkString("/"))" class="btn btn-danger">Cancel</a>
|
||||
} else {
|
||||
<a href="@helpers.url(repository)/blob/@helpers.encodeRefName(branch)/@{(pathList ++ Seq(fileName.get)).mkString("/")}" class="btn btn-danger">Cancel</a>
|
||||
<a href="@helpers.url(repository)/blob/@helpers.encodeRefName((branch :: pathList ++ Seq(fileName.get)).mkString("/"))" class="btn btn-danger">Cancel</a>
|
||||
}
|
||||
<input type="submit" id="commitButton" class="btn btn-success" value="Commit changes" disabled="true"/>
|
||||
<input type="hidden" id="charset" name="charset" value="@content.charset"/>
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
if(branch == repository.repository.defaultBranch){
|
||||
s"${repository.owner}/${repository.name}"
|
||||
} else {
|
||||
s"${repository.owner}/${repository.name} at ${helpers.encodeRefName(branch)}"
|
||||
s"${repository.owner}/${repository.name} at ${branch}"
|
||||
}
|
||||
} else {
|
||||
s"${(repository.name :: pathList).mkString("/")} at ${helpers.encodeRefName(branch)} - ${repository.owner}/${repository.name}"
|
||||
s"${(repository.name :: pathList).mkString("/")} at ${branch} - ${repository.owner}/${repository.name}"
|
||||
}, Some(repository)) {
|
||||
@gitbucket.core.html.menu("files", repository, Some(branch), info, error){
|
||||
@if(pathList.isEmpty) {
|
||||
@@ -32,9 +32,9 @@
|
||||
<div class="head" style="height: 24px;">
|
||||
<div class="pull-right">
|
||||
<div class="btn-group">
|
||||
<a href="@helpers.url(repository)/tree/@latestCommit.id/@pathList.mkString("/")" data-hotkey="y" style="display: none;">Transfer to URL with SHA</a>
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName((latestCommit.id :: pathList).mkString("/"))" data-hotkey="y" style="display: none;">Transfer to URL with SHA</a>
|
||||
<a href="@helpers.url(repository)/find/@helpers.encodeRefName(branch)" class="btn btn-sm btn-default" data-hotkey="t"><i class="octicon octicon-search"></i></a>
|
||||
<a href="@helpers.url(repository)/commits/@helpers.encodeRefName(branch)/@pathList.mkString("/")" class="btn btn-sm btn-default"><i class="octicon octicon-history"></i> @if(commitCount > 10000){10000+} else {@commitCount} @helpers.plural(commitCount, "commit")</a>
|
||||
<a href="@helpers.url(repository)/commits/@helpers.encodeRefName((branch :: pathList).mkString("/"))" class="btn btn-sm btn-default"><i class="octicon octicon-history"></i> @if(commitCount > 10000){10000+} else {@commitCount} @helpers.plural(commitCount, "commit")</a>
|
||||
</div>
|
||||
</div>
|
||||
@if(pathList.isEmpty){
|
||||
@@ -84,14 +84,14 @@
|
||||
@if(pathList.nonEmpty){
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)">@repository.name</a> /
|
||||
@pathList.zipWithIndex.map { case (section, i) =>
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)/@pathList.take(i + 1).mkString("/")">@section</a> /
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName((branch :: pathList.take(i + 1)).mkString("/"))">@section</a> /
|
||||
}
|
||||
}
|
||||
</div>
|
||||
@if(hasWritePermission){
|
||||
<div class="btn-group pull-left" style="margin-left: 4px;">
|
||||
<a href="@helpers.url(repository)/new/@helpers.encodeRefName(branch)/@pathList.mkString("/")" class="btn btn-sm btn-default pc" title="Create a new file"><i class="octicon octicon-plus"></i></a>
|
||||
<a href="@helpers.url(repository)/upload/@helpers.encodeRefName(branch)/@pathList.mkString("/")" class="btn btn-sm btn-default pc" title="Upload files"><i class="octicon octicon-cloud-upload"></i></a>
|
||||
<a href="@helpers.url(repository)/new/@helpers.encodeRefName((branch :: pathList).mkString("/"))" class="btn btn-sm btn-default pc" title="Create a new file"><i class="octicon octicon-plus"></i></a>
|
||||
<a href="@helpers.url(repository)/upload/@helpers.encodeRefName((branch :: pathList).mkString("/"))" class="btn btn-sm btn-default pc" title="Upload files"><i class="octicon octicon-cloud-upload"></i></a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -133,7 +133,7 @@
|
||||
@if(pathList.size > 0){
|
||||
<tr>
|
||||
<td width="16" class="file-icon"></td>
|
||||
<td><a href="@helpers.url(repository)@if(pathList.size > 1){/tree/@helpers.encodeRefName(branch)/@pathList.init.mkString("/")}">..</a></td>
|
||||
<td><a href="@helpers.url(repository)@if(pathList.size > 1){/tree/@helpers.encodeRefName(branch)/@helpers.encodeRefName(pathList.init.mkString("/"))}">..</a></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
@@ -173,7 +173,7 @@
|
||||
</span>
|
||||
}
|
||||
case None => {
|
||||
<a href={helpers.url(repository) + "/tree" + (branch :: pathList).map(helpers.encodeRefName).mkString("/", "/", "/") + helpers.encodeRefName(file.name)}>
|
||||
<a href={helpers.url(repository) + "/tree" + helpers.encodeRefName((branch :: pathList).mkString("/", "/", "/") + file.name)}>
|
||||
<span class="simplified-path">{file.name.split("/").toList.init match {
|
||||
case Nil => ""
|
||||
case list => list.mkString("", "/", "/")
|
||||
@@ -183,7 +183,7 @@
|
||||
}
|
||||
}}
|
||||
} else {
|
||||
<a href="@helpers.url(repository)/blob@{(branch :: pathList).map(helpers.encodeRefName).mkString("/", "/", "/")}@{helpers.encodeRefName(file.name)}">@file.name</a>
|
||||
<a href="@helpers.url(repository)/blob@{helpers.encodeRefName((branch :: pathList).mkString("/", "/", "/") + file.name)}">@file.name</a>
|
||||
}
|
||||
</td>
|
||||
<td class="ellipsis-cell" style="width: 70%;">
|
||||
|
||||
@@ -59,19 +59,19 @@ $(function(){
|
||||
if(e.keyCode == 40){ // DOWN
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
changeCursor(cursor+1);
|
||||
}else if(e.keyCode==38){ // UP
|
||||
changeCursor(cursor + 1);
|
||||
}else if(e.keyCode == 38){ // UP
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
changeCursor(cursor-1);
|
||||
}else if(e.keyCode==13){ // ENTER
|
||||
changeCursor(cursor - 1);
|
||||
}else if(e.keyCode == 13){ // ENTER
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
target = $(".tree-browser-result.navigation-focus a");
|
||||
if(target[0]){
|
||||
target[0].click();
|
||||
}
|
||||
}else if(e.keyCode==27){ // ESC
|
||||
}else if(e.keyCode == 27){ // ESC
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
history.back();
|
||||
@@ -90,23 +90,25 @@ $(function(){
|
||||
}
|
||||
function filter(){
|
||||
var v = $('#tree-finder-field').val();
|
||||
if(v==preKeyword || paths.length==0){
|
||||
if(v == preKeyword || paths.length == 0){
|
||||
return;
|
||||
}
|
||||
scrollIntoView('#tree-finder-field');
|
||||
preKeyword=v;
|
||||
cursor=0;
|
||||
preKeyword = v;
|
||||
cursor = 0;
|
||||
var p = string_score_sort(v, paths, 50);
|
||||
res.html("");
|
||||
if(p.length==0){
|
||||
if(p.length == 0){
|
||||
$(".no-results").show();
|
||||
return;
|
||||
}else{
|
||||
$(".no-results").hide();
|
||||
for(var i=0;i < p.length;i++){
|
||||
for(var i = 0; i < p.length; i++){
|
||||
var row = template.clone();
|
||||
row.find("a").attr("href",pathBase+"/"+p[i].string).html(string_score_highlight(p[i], '<b>'));
|
||||
if(cursor==i){
|
||||
// console.log('Path base: ' + pathBase);
|
||||
// console.log('Path rest ' + p[i].string);
|
||||
row.find("a").attr("href", pathBase + "/" + encodeURIComponent(p[i].string).replace('%2F', '/')).html(string_score_highlight(p[i], '<b>'));
|
||||
if(cursor == i){
|
||||
row.addClass("navigation-focus");
|
||||
}
|
||||
row.appendTo(res);
|
||||
@@ -116,4 +118,4 @@ $(function(){
|
||||
});
|
||||
</script>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<div class="head">
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)">@repository.name</a> /
|
||||
@pathList.zipWithIndex.map { case (section, i) =>
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)/@pathList.take(i + 1).mkString("/")">@section</a> /
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch + "/" + pathList.take(i + 1).mkString("/"))">@section</a> /
|
||||
}
|
||||
<input type="hidden" name="branch" id="branch" value="@branch"/>
|
||||
<input type="hidden" name="path" id="path" value="@pathList.mkString("/")"/>
|
||||
@@ -38,7 +38,7 @@
|
||||
<input type="text" name="message" class="form-control"/>
|
||||
</div>
|
||||
<div style="text-align: right;">
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch)/@{pathList.mkString("/")}" class="btn btn-danger">Cancel</a>
|
||||
<a href="@helpers.url(repository)/tree/@helpers.encodeRefName(branch + "/" + pathList.mkString("/"))" class="btn btn-danger">Cancel</a>
|
||||
<input type="submit" id="commit" class="btn btn-success" value="Commit changes" disabled="true"/>
|
||||
<input type="hidden" id="upload-files-data" name="uploadFiles" value=""/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user