diff --git a/changelogs/unreleased/sh-fix-diffs-with-leading-slashes.yml b/changelogs/unreleased/sh-fix-diffs-with-leading-slashes.yml new file mode 100644 index 0000000000000000000000000000000000000000..4744da003bb079f95c506531212bcb5a1e0e3fcd --- /dev/null +++ b/changelogs/unreleased/sh-fix-diffs-with-leading-slashes.yml @@ -0,0 +1,5 @@ +--- +title: Gracefully handle diff paths with leading slashes +merge_request: 1857 +author: +type: fixed diff --git a/internal/service/diff/commit.go b/internal/service/diff/commit.go index 7f46bdc9c29ea5052af168ced8db17d34aa7d6f0..f6248925493114a2125c80f9aad7ebe78813a8a5 100644 --- a/internal/service/diff/commit.go +++ b/internal/service/diff/commit.go @@ -3,6 +3,7 @@ package diff import ( "context" "fmt" + "strings" grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" log "github.com/sirupsen/logrus" @@ -52,7 +53,8 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff } if len(paths) > 0 { for _, path := range paths { - cmd.PostSepArgs = append(cmd.PostSepArgs, string(path)) + s := strings.TrimPrefix(string(path), "/") + cmd.PostSepArgs = append(cmd.PostSepArgs, s) } } diff --git a/internal/service/diff/commit_test.go b/internal/service/diff/commit_test.go index 89610cc1a41d0f64150449cef6b86caaa9038758..ded9a9e5a4e5597aa471ea344fd679e8140f7997 100644 --- a/internal/service/diff/commit_test.go +++ b/internal/service/diff/commit_test.go @@ -197,6 +197,7 @@ func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) { IgnoreWhitespaceChange: false, Paths: [][]byte{ []byte("CONTRIBUTING.md"), + []byte("/MAINTENANCE.md"), []byte("README.md"), []byte("gitaly/named-file-with-mods"), []byte("gitaly/mode-file-with-mods"), @@ -221,6 +222,16 @@ func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) { Binary: false, Patch: testhelper.MustReadFile(t, "testdata/contributing-md-chunks.txt"), }, + { + FromID: "95d9f0a5e7bb054e9dd3975589b8dfc689e20e88", + ToID: "5d9c7c0470bf368d61d9b6cd076300dc9d061f14", + OldMode: 0100644, + NewMode: 0100644, + FromPath: []byte("MAINTENANCE.md"), + ToPath: []byte("MAINTENANCE.md"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/maintenance-file-with-mods-chunks.txt"), + }, { FromID: "faaf198af3a36dbf41961466703cc1d47c61d051", ToID: "877cee6ab11f9094e1bcdb7f1fd9c0001b572185", diff --git a/internal/service/diff/testdata/maintenance-file-with-mods-chunks.txt b/internal/service/diff/testdata/maintenance-file-with-mods-chunks.txt new file mode 100644 index 0000000000000000000000000000000000000000..093586fb0e946f3c0d807d0220d3b1ebc0d95d61 --- /dev/null +++ b/internal/service/diff/testdata/maintenance-file-with-mods-chunks.txt @@ -0,0 +1,9 @@ +@@ -16,7 +16,7 @@ GitLab follows the [Semantic Versioning](http://semver.org/) for its releases: + incorrect behavior. + + The current stable release will receive security patches and bug fixes +-(eg. `5.0` -> `5.0.1`). Feature releases will mark the next supported stable ++(eg. `5.0` -> `5.0.1`). Feature releases will mark the next supported stable + release where the minor version is increased numerically by increments of one + (eg. `5.0 -> 5.1`). +