Skip to content

repo_editor: check both styles of os.PathSeparator in all systems #7005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
repo_editor: check both styles of os.PathSeparator in all systems
  • Loading branch information
unknwon committed Jun 4, 2022
commit 1bd3d10ec7288efd3eb71b9e8b755c22aeb685ac
6 changes: 4 additions & 2 deletions internal/db/repo_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,12 @@ type UploadRepoFileOptions struct {
// path of the repository.
func isRepositoryGitPath(path string) bool {
return strings.HasSuffix(path, ".git") ||
strings.Contains(path, ".git"+string(os.PathSeparator)) ||
strings.Contains(path, ".git/") ||
strings.Contains(path, `.git\`) ||
// Windows treats ".git." the same as ".git"
strings.HasSuffix(path, ".git.") ||
strings.Contains(path, ".git."+string(os.PathSeparator))
strings.Contains(path, ".git./") ||
strings.Contains(path, `.git.\`)
}

func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions) error {
Expand Down
45 changes: 29 additions & 16 deletions internal/db/repo_editor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package db

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -16,23 +15,37 @@ func Test_isRepositoryGitPath(t *testing.T) {
path string
wantVal bool
}{
{path: filepath.Join(".", ".git"), wantVal: true},
{path: filepath.Join(".", ".git", ""), wantVal: true},
{path: filepath.Join(".", ".git", "hooks", "pre-commit"), wantVal: true},
{path: filepath.Join(".git", "hooks"), wantVal: true},
{path: filepath.Join("dir", ".git"), wantVal: true},

{path: filepath.Join(".", ".git."), wantVal: true},
{path: filepath.Join(".", ".git.", ""), wantVal: true},
{path: filepath.Join(".", ".git.", "hooks", "pre-commit"), wantVal: true},
{path: filepath.Join(".git.", "hooks"), wantVal: true},
{path: filepath.Join("dir", ".git."), wantVal: true},

{path: filepath.Join(".gitignore"), wantVal: false},
{path: filepath.Join("dir", ".gitkeep"), wantVal: false},
{path: ".git", wantVal: true},
{path: "./.git", wantVal: true},
{path: ".git/hooks/pre-commit", wantVal: true},
{path: ".git/hooks", wantVal: true},
{path: "dir/.git", wantVal: true},

{path: ".gitignore", wantVal: false},
{path: "dir/.gitkeep", wantVal: false},

// Windows-specific
{path: `.git\`, wantVal: true},
{path: `.git\hooks\pre-commit`, wantVal: true},
{path: `.git\hooks`, wantVal: true},
{path: `dir\.git`, wantVal: true},

{path: `.\.git.`, wantVal: true},
{path: `.\.git.\`, wantVal: true},
{path: `.git.\hooks\pre-commit`, wantVal: true},
{path: `.git.\hooks`, wantVal: true},
{path: `dir\.git.`, wantVal: true},

{path: "./.git.", wantVal: true},
{path: "./.git./", wantVal: true},
{path: ".git./hooks/pre-commit", wantVal: true},
{path: ".git./hooks", wantVal: true},
{path: "dir/.git.", wantVal: true},

{path: `dir\.gitkeep`, wantVal: false},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
t.Run(test.path, func(t *testing.T) {
assert.Equal(t, test.wantVal, isRepositoryGitPath(test.path))
})
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy