diff options
author | John Cai <jcai@gitlab.com> | 2022-10-10 17:15:53 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2022-10-10 17:15:53 +0300 |
commit | 894bd7d8bd67dd40e2f0bdb002d4632884cdb9e6 (patch) | |
tree | c1f470136b632792c23c2100f110e9fcc2e4b244 | |
parent | 99b5528b66b23c1a8399027ecdef306267e668ae (diff) |
git: Validate \\ in refname
In ae728915 (refs: Return structured errors for DeleteRefs 2022-05-12),
we started to validate ref format and return a structured error. The
existence of a backslash is not something we currently validate, and
instead we rely on the `prepare` step to catch this error. We should
catch this in the ref validation step instead.
Changelog: changed
-rw-r--r-- | internal/git/revision.go | 3 | ||||
-rw-r--r-- | internal/git/revision_test.go | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/internal/git/revision.go b/internal/git/revision.go index 89d1e05d4..45814cfad 100644 --- a/internal/git/revision.go +++ b/internal/git/revision.go @@ -21,6 +21,9 @@ func validateRevision(revision []byte, allowEmpty bool) error { if bytes.Contains(revision, []byte(":")) { return fmt.Errorf("revision can't contain ':'") } + if bytes.Contains(revision, []byte("\\")) { + return fmt.Errorf("revision can't contain '\\'") + } return nil } diff --git a/internal/git/revision_test.go b/internal/git/revision_test.go index edd574d5c..afb05c2e6 100644 --- a/internal/git/revision_test.go +++ b/internal/git/revision_test.go @@ -63,6 +63,11 @@ func TestValidateRevision(t *testing.T) { revision: "foo/bar:baz", expectedErr: fmt.Errorf("revision can't contain ':'"), }, + { + desc: "backslash", + revision: "foo\\bar\\baz", + expectedErr: fmt.Errorf("revision can't contain '\\'"), + }, } { t.Run(tc.desc, func(t *testing.T) { require.Equal(t, tc.expectedErr, ValidateRevision([]byte(tc.revision))) |