mirror of
https://dev.sigpipe.me/dashie/git.txt
synced 2025-10-06 02:12:39 +02:00
Fix handling of files within a subdirectory
This commit is contained in:
2
TODO.org
2
TODO.org
@@ -8,7 +8,7 @@
|
||||
* Ways of improvement
|
||||
** TODO Merge AssignUser and AssignRepository ?
|
||||
** TODO Cleanup gogs imports of unused bits
|
||||
** TODO Can't add files with filename "/some/thing/foo.bar"
|
||||
** DONE Can't add files with filename "/some/thing/foo.bar"
|
||||
** DONE Investigate the non-working context.Flash when not using a redirect
|
||||
** DONE Correctly handle filenames with a /, like raw view
|
||||
** DONE strip '/' from filenames
|
||||
|
@@ -58,6 +58,7 @@ func NewPost(ctx *context.Context, f form.Gitxt) {
|
||||
for i := range f.FilesFilename {
|
||||
// For each filename sanitize it
|
||||
f.FilesFilename[i] = sanitize.Filename(f.FilesFilename[i])
|
||||
f.FilesFilename[i] = sanitize.RemoveFirstSlash(f.FilesFilename[i])
|
||||
if len(f.FilesFilename[i]) == 0 || f.FilesFilename[i] == "." {
|
||||
// If length is zero, use default filename
|
||||
f.FilesFilename[i] = fmt.Sprintf("gitxt%d.txt", i)
|
||||
|
@@ -133,7 +133,9 @@ func cleanString(s string, r *regexp.Regexp) string {
|
||||
}
|
||||
|
||||
// We are very restrictive as this could be intended for ascii url slugs
|
||||
var illegalPath = regexp.MustCompile(`[^[:alnum:]\~\-\_\./]`)
|
||||
var illegalPath = regexp.MustCompile(`[^[:alnum:]\~\-\_\.]/`)
|
||||
|
||||
var slashes = regexp.MustCompile(`^[/]+`)
|
||||
|
||||
// Filename will clean illegal characters
|
||||
func Filename(s string) string {
|
||||
@@ -146,3 +148,8 @@ func Filename(s string) string {
|
||||
// NB this may be of length 0, caller must check
|
||||
return filePath
|
||||
}
|
||||
|
||||
// RemoveFirstSlash remove the firstS slashes of filename
|
||||
func RemoveFirstSlash(s string) string {
|
||||
return slashes.ReplaceAllString(s, "")
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@
|
||||
{{range $entryFile := .repoFiles}}
|
||||
<div class="gitxt_file">
|
||||
<div class="header clearfix" id="file_{{$entryFile.Path}}">
|
||||
<div class="left"><i class="fa fa-file-code-o" aria-hidden="true"></i> <a href="#file_{{$entryFile.Path}}">{{$entryFile.Path}}</a> <span class="file_size">{{FileSize $entryFile.Size}}</span> <small>({{$entryFile.MimeType}})</small></div>
|
||||
<div class="left"><i class="fa fa-file-code-o" aria-hidden="true"></i> <a href="#file_{{$entryFile.Path}}">/{{$entryFile.Path}}</a> <span class="file_size">{{FileSize $entryFile.Size}}</span> <small>({{$entryFile.MimeType}})</small></div>
|
||||
<div class="right"><a class="btn btn-xs btn-default" href="{{AppSubURL}}/{{$.repoOwnerUsername}}/{{$.repoHash}}/raw/{{$entryFile.Path}}">{{$.i18n.Tr "gitxt_view.raw_file"}}</a></div>
|
||||
</div>
|
||||
<div class="gitxt_content">
|
||||
|
Reference in New Issue
Block a user