diff options
author | Quang-Minh Nguyen <qmnguyen@gitlab.com> | 2023-03-14 13:40:15 +0300 |
---|---|---|
committer | Quang-Minh Nguyen <qmnguyen@gitlab.com> | 2023-03-16 05:50:46 +0300 |
commit | 936640076881092ad60202823f2dc81828aa4b6d (patch) | |
tree | aa79a72dd5362f5185f5b55e8265d7106a9625a6 /internal | |
parent | 5c42c9509ff0fab716f7b903b9dc4be77f1c15d9 (diff) |
lint: Fix manual quote interpolation offenses
This commit fixes manually quoted string interpolation with '%s' and
"%s". Quoting this way doesn't escape special characters such as endline
and makes debugging harder later. We encourage to use %q verb instead.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/git/command_factory_test.go | 1 | ||||
-rw-r--r-- | internal/git2go/commit.go | 2 | ||||
-rw-r--r-- | internal/gitaly/config/config_test.go | 1 | ||||
-rw-r--r-- | internal/gitaly/hook/postreceive_test.go | 2 | ||||
-rw-r--r-- | internal/gitaly/hook/prereceive_test.go | 1 | ||||
-rw-r--r-- | internal/gitaly/hook/update_test.go | 1 | ||||
-rw-r--r-- | internal/gitaly/service/diff/patch_id_test.go | 1 | ||||
-rw-r--r-- | internal/gitaly/service/hook/pack_objects_test.go | 6 | ||||
-rw-r--r-- | internal/gitaly/service/hook/pre_receive_test.go | 1 | ||||
-rw-r--r-- | internal/gitaly/service/operations/submodules_test.go | 38 | ||||
-rw-r--r-- | internal/gitaly/service/repository/fetch_remote_test.go | 1 | ||||
-rw-r--r-- | internal/gitaly/service/repository/fsck_test.go | 1 | ||||
-rw-r--r-- | internal/gitaly/service/smarthttp/upload_pack_test.go | 1 | ||||
-rw-r--r-- | internal/gitaly/service/ssh/upload_pack_test.go | 1 | ||||
-rw-r--r-- | internal/gitlab/client/httpclient.go | 2 | ||||
-rw-r--r-- | internal/gitlab/http_client.go | 2 | ||||
-rw-r--r-- | internal/praefect/datastore/listener_test.go | 1 |
17 files changed, 37 insertions, 26 deletions
diff --git a/internal/git/command_factory_test.go b/internal/git/command_factory_test.go index 28a88d609..90cc45908 100644 --- a/internal/git/command_factory_test.go +++ b/internal/git/command_factory_test.go @@ -515,6 +515,7 @@ func TestExecCommandFactory_GitVersion(t *testing.T) { generateVersionScript := func(version string) func(git.ExecutionEnvironment) string { return func(git.ExecutionEnvironment) string { + //nolint:gitaly-linters return fmt.Sprintf( `#!/usr/bin/env bash echo '%s' diff --git a/internal/git2go/commit.go b/internal/git2go/commit.go index 115c354e2..fd14b6d45 100644 --- a/internal/git2go/commit.go +++ b/internal/git2go/commit.go @@ -55,7 +55,7 @@ func (err IndexError) Error() string { case ErrFileNotFound: return "A file with this name doesn't exist" case ErrInvalidPath: - return fmt.Sprintf("invalid path: '%s'", err.Path) + return fmt.Sprintf("invalid path: %q", err.Path) default: panic(fmt.Sprintf("unhandled IndexErrorType: %v", err.Type)) } diff --git a/internal/gitaly/config/config_test.go b/internal/gitaly/config/config_test.go index 154bf5ca5..61575fb59 100644 --- a/internal/gitaly/config/config_test.go +++ b/internal/gitaly/config/config_test.go @@ -600,6 +600,7 @@ func TestLoadGracefulRestartTimeout(t *testing.T) { func TestGitlabShellDefaults(t *testing.T) { gitlabShellDir := "/dir" + //nolint:gitaly-linters tmpFile := strings.NewReader(fmt.Sprintf(`[gitlab-shell] dir = '%s'`, gitlabShellDir)) cfg, err := Load(tmpFile) diff --git a/internal/gitaly/hook/postreceive_test.go b/internal/gitaly/hook/postreceive_test.go index d498ec0cc..b15b51906 100644 --- a/internal/gitaly/hook/postreceive_test.go +++ b/internal/gitaly/hook/postreceive_test.go @@ -382,7 +382,7 @@ func TestPostReceive_quarantine(t *testing.T) { gittest.WriteCustomHook(t, repoPath, "post-receive", []byte(fmt.Sprintf( `#!/bin/sh - git cat-file -p '%s' || true + git cat-file -p %q || true `, blobID.String()))) for repo, isQuarantined := range map[*gitalypb.Repository]bool{ diff --git a/internal/gitaly/hook/prereceive_test.go b/internal/gitaly/hook/prereceive_test.go index 294c15941..54e4b22ea 100644 --- a/internal/gitaly/hook/prereceive_test.go +++ b/internal/gitaly/hook/prereceive_test.go @@ -196,6 +196,7 @@ func TestPrereceive_quarantine(t *testing.T) { t, gitlab.MockAllowed, gitlab.MockPreReceive, gitlab.MockPostReceive, )) + //nolint:gitaly-linters gittest.WriteCustomHook(t, repoPath, "pre-receive", []byte(fmt.Sprintf( `#!/bin/sh git cat-file -p '%s' || true diff --git a/internal/gitaly/hook/update_test.go b/internal/gitaly/hook/update_test.go index 6c968ea47..d34cb632c 100644 --- a/internal/gitaly/hook/update_test.go +++ b/internal/gitaly/hook/update_test.go @@ -227,6 +227,7 @@ func TestUpdate_quarantine(t *testing.T) { t, gitlab.MockAllowed, gitlab.MockPreReceive, gitlab.MockPostReceive, )) + //nolint:gitaly-linters gittest.WriteCustomHook(t, repoPath, "update", []byte(fmt.Sprintf( `#!/bin/sh git cat-file -p '%s' || true diff --git a/internal/gitaly/service/diff/patch_id_test.go b/internal/gitaly/service/diff/patch_id_test.go index 1ac3d85fc..386ad45c9 100644 --- a/internal/gitaly/service/diff/patch_id_test.go +++ b/internal/gitaly/service/diff/patch_id_test.go @@ -239,6 +239,7 @@ func TestGetPatchID(t *testing.T) { OldRevision: []byte(fmt.Sprintf("%s:file", oldCommit)), NewRevision: []byte(fmt.Sprintf("%s:file", newCommit)), }, + //nolint:gitaly-linters expectedErr: structerr.New("waiting for git-diff: exit status 128"). WithInterceptedMetadata("stderr", fmt.Sprintf("fatal: path 'file' does not exist in '%s'\n", oldCommit)), } diff --git a/internal/gitaly/service/hook/pack_objects_test.go b/internal/gitaly/service/hook/pack_objects_test.go index 8d1344983..49deba854 100644 --- a/internal/gitaly/service/hook/pack_objects_test.go +++ b/internal/gitaly/service/hook/pack_objects_test.go @@ -754,7 +754,7 @@ func testPackObjectsConcurrency(t *testing.T, ctx context.Context) { testutil.GatherAndCompare(registry, bytes.NewBufferString(fmt.Sprintf(`# HELP gitaly_pack_objects_in_progress Gauge of number of concurrent in-progress calls # TYPE gitaly_pack_objects_in_progress gauge -gitaly_pack_objects_in_progress{type="%s"} 1 +gitaly_pack_objects_in_progress{type=%q} 1 `, keyType)), "gitaly_pack_objects_in_progress")) ticker.Tick() @@ -770,10 +770,10 @@ gitaly_pack_objects_in_progress{type="%s"} 1 expectedMetrics := bytes.NewBufferString(fmt.Sprintf(`# HELP gitaly_pack_objects_dropped_total Number of requests dropped from the queue # TYPE gitaly_pack_objects_dropped_total counter -gitaly_pack_objects_dropped_total{reason="max_time", type="%s"} 1 +gitaly_pack_objects_dropped_total{reason="max_time", type=%q} 1 # HELP gitaly_pack_objects_queued Gauge of number of queued calls # TYPE gitaly_pack_objects_queued gauge -gitaly_pack_objects_queued{type="%s"} 0 +gitaly_pack_objects_queued{type=%q} 0 `, keyType, keyType)) require.NoError(t, diff --git a/internal/gitaly/service/hook/pre_receive_test.go b/internal/gitaly/service/hook/pre_receive_test.go index 1515618de..14a0289cc 100644 --- a/internal/gitaly/service/hook/pre_receive_test.go +++ b/internal/gitaly/service/hook/pre_receive_test.go @@ -335,6 +335,7 @@ func TestPreReceiveHook_CustomHookErrors(t *testing.T) { customHookReturnCode := int32(128) customHookReturnMsg := "custom hook error" + //nolint:gitaly-linters gittest.WriteCustomHook(t, repoPath, "pre-receive", []byte(fmt.Sprintf(`#!/usr/bin/env bash echo '%s' 1>&2 exit %d diff --git a/internal/gitaly/service/operations/submodules_test.go b/internal/gitaly/service/operations/submodules_test.go index 88d2306e7..a5aac1610 100644 --- a/internal/gitaly/service/operations/submodules_test.go +++ b/internal/gitaly/service/operations/submodules_test.go @@ -55,7 +55,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -85,7 +85,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -115,7 +115,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "foo/sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "foo/sub", subRepoPath), }, gittest.TreeEntry{ Mode: "040000", @@ -161,7 +161,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -203,7 +203,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -232,7 +232,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -261,7 +261,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -290,7 +290,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -319,7 +319,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -349,7 +349,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -378,7 +378,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -407,7 +407,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -437,7 +437,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -469,7 +469,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -501,7 +501,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -584,7 +584,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -615,7 +615,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -648,7 +648,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, )) @@ -684,7 +684,7 @@ func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { gittest.TreeEntry{ Mode: "100644", Path: ".gitmodules", - Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + Content: fmt.Sprintf(`[submodule %q]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), }, gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, ), diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go index 96dd1f999..3ae37edca 100644 --- a/internal/gitaly/service/repository/fetch_remote_test.go +++ b/internal/gitaly/service/repository/fetch_remote_test.go @@ -954,6 +954,7 @@ func TestFetchRemote_sshCommand(t *testing.T) { // We ain't got a nice way to intercept the SSH call, so we just write a custom git command // which simply prints the GIT_SSH_COMMAND environment variable. gitCmdFactory := gittest.NewInterceptingCommandFactory(t, ctx, cfg, func(execEnv git.ExecutionEnvironment) string { + //nolint:gitaly-linters return fmt.Sprintf( `#!/usr/bin/env bash diff --git a/internal/gitaly/service/repository/fsck_test.go b/internal/gitaly/service/repository/fsck_test.go index bbaf8e617..51dd64771 100644 --- a/internal/gitaly/service/repository/fsck_test.go +++ b/internal/gitaly/service/repository/fsck_test.go @@ -83,6 +83,7 @@ func TestFsck(t *testing.T) { return setupData{ repo: repo, expectedResponse: &gitalypb.FsckResponse{ + //nolint:gitaly-linters Error: []byte(fmt.Sprintf("fatal: not a git repository: '%s'\n", repoPath)), }, } diff --git a/internal/gitaly/service/smarthttp/upload_pack_test.go b/internal/gitaly/service/smarthttp/upload_pack_test.go index a53da2294..28a35c517 100644 --- a/internal/gitaly/service/smarthttp/upload_pack_test.go +++ b/internal/gitaly/service/smarthttp/upload_pack_test.go @@ -234,6 +234,7 @@ func testServerPostUploadPackUsesPackObjectsHook(t *testing.T, ctx context.Conte cfg.BinDir = testhelper.TempDir(t) outputPath := filepath.Join(cfg.BinDir, "output") + //nolint:gitaly-linters hookScript := fmt.Sprintf("#!/bin/sh\necho 'I was invoked' >'%s'\nshift\nexec git \"$@\"\n", outputPath) // We're using a custom pack-objects hook for git-upload-pack. In order diff --git a/internal/gitaly/service/ssh/upload_pack_test.go b/internal/gitaly/service/ssh/upload_pack_test.go index 900e05d62..3aa4f5c1b 100644 --- a/internal/gitaly/service/ssh/upload_pack_test.go +++ b/internal/gitaly/service/ssh/upload_pack_test.go @@ -662,6 +662,7 @@ func TestUploadPack_packObjectsHook(t *testing.T) { // custom script which replaces the hook binary. It doesn't do anything // special, but writes an error message and errors out and should thus // cause the clone to fail with this error message. + // nolint:gitaly-linters testhelper.WriteExecutable(t, cfg.BinaryPath("gitaly-hooks"), []byte(fmt.Sprintf( `#!/usr/bin/env bash set -eo pipefail diff --git a/internal/gitlab/client/httpclient.go b/internal/gitlab/client/httpclient.go index 9333d4881..b15643f4a 100644 --- a/internal/gitlab/client/httpclient.go +++ b/internal/gitlab/client/httpclient.go @@ -60,7 +60,7 @@ func validateCaFile(filename string) error { if _, err := os.Stat(filename); err != nil { if os.IsNotExist(err) { - return fmt.Errorf("cannot find cafile '%s': %w", filename, ErrCafileNotFound) + return fmt.Errorf("cannot find cafile %q: %w", filename, ErrCafileNotFound) } return err diff --git a/internal/gitlab/http_client.go b/internal/gitlab/http_client.go index 2f02a3d3f..77599cb18 100644 --- a/internal/gitlab/http_client.go +++ b/internal/gitlab/http_client.go @@ -128,7 +128,7 @@ func (a *allowedRequest) parseAndSetGLID(glID string) error { } if !glIDRegex.MatchString(value) { - return fmt.Errorf("gl_id='%s' is invalid", glID) + return fmt.Errorf("gl_id=%q is invalid", glID) } return nil diff --git a/internal/praefect/datastore/listener_test.go b/internal/praefect/datastore/listener_test.go index 38db2a1a4..dae8c52ab 100644 --- a/internal/praefect/datastore/listener_test.go +++ b/internal/praefect/datastore/listener_test.go @@ -51,6 +51,7 @@ func TestListener_Listen(t *testing.T) { notifyListener := func(t *testing.T, channels []string, payload string) { t.Helper() for _, channel := range channels { + //nolint:gitaly-linters _, err := db.Exec(fmt.Sprintf(`NOTIFY %s, '%s'`, channel, payload)) assert.NoError(t, err) } |