diff options
author | Stan Hu <stanhu@gmail.com> | 2021-02-18 13:13:29 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2021-02-20 01:07:51 +0300 |
commit | af700c819ad513ba9c5107b429aafba512a9a51c (patch) | |
tree | c19ccf7d0ecba9d7a57801f7efc0179ccc828cf6 | |
parent | e8596a35bf6cf664516763ac5724249ee2c0bcf1 (diff) |
Fix 500 errors in Wiki pages with trailers containing UTF-8
When Wiki pages have trailers such as `Signed-Off-By` that include UTF-8
characters, users would see encoding errors because Protobuf requires
calling the `.b` method on a UTF-8 encoded string
(https://github.com/protocolbuffers/protobuf/issues/4228).
Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/301154
-rw-r--r-- | changelogs/unreleased/sh-fix-wiki-trailers-500-error.yml | 5 | ||||
-rw-r--r-- | internal/gitaly/service/wiki/find_page_test.go | 46 | ||||
-rw-r--r-- | ruby/lib/gitaly_server/utils.rb | 2 |
3 files changed, 52 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-fix-wiki-trailers-500-error.yml b/changelogs/unreleased/sh-fix-wiki-trailers-500-error.yml new file mode 100644 index 000000000..9dce76cca --- /dev/null +++ b/changelogs/unreleased/sh-fix-wiki-trailers-500-error.yml @@ -0,0 +1,5 @@ +--- +title: Fix 500 errors in Wiki pages with trailers containing UTF-8 +merge_request: 3169 +author: +type: fixed diff --git a/internal/gitaly/service/wiki/find_page_test.go b/internal/gitaly/service/wiki/find_page_test.go index 094377f9e..459a210c5 100644 --- a/internal/gitaly/service/wiki/find_page_test.go +++ b/internal/gitaly/service/wiki/find_page_test.go @@ -1,6 +1,7 @@ package wiki import ( + "fmt" "io" "testing" @@ -466,3 +467,48 @@ func TestInvalidWikiFindPageRequestRevision(t *testing.T) { _, err = stream.Recv() testhelper.RequireGrpcError(t, err, codes.InvalidArgument) } + +func TestSuccessfulWikiFindPageRequestWithTrailers(t *testing.T) { + wikiRepo, worktreePath, cleanupFn := testhelper.InitRepoWithWorktree(t) + defer cleanupFn() + + committerName := "Scróoge McDuck" // Include UTF-8 to ensure encoding is handled + committerEmail := "scrooge@mcduck.com" + + testhelper.MustRunCommand(t, nil, "git", "-C", worktreePath, + "-c", fmt.Sprintf("user.name=%s", committerName), + "-c", fmt.Sprintf("user.email=%s", committerEmail), + "commit", "--allow-empty", "-m", "master branch, empty commit") + + locator := config.NewLocator(config.Config) + stop, serverSocketPath := runWikiServiceServer(t, locator) + defer stop() + + client, conn := newWikiClient(t, serverSocketPath) + defer conn.Close() + + page1Name := "Home Pagé" + createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page1Name}) + + testhelper.MustRunCommand(t, nil, "git", "-C", worktreePath, + "-c", fmt.Sprintf("user.name=%s", committerName), + "-c", fmt.Sprintf("user.email=%s", committerEmail), + "commit", "--amend", "-m", "Empty commit", "-s") + + ctx, cancel := testhelper.Context() + defer cancel() + + request := &gitalypb.WikiFindPageRequest{ + Repository: wikiRepo, + Title: []byte(page1Name), + } + + c, err := client.WikiFindPage(ctx, request) + require.NoError(t, err) + + receivedPage := readFullWikiPageFromWikiFindPageClient(t, c) + require.Equal(t, page1Name, string(receivedPage.Name)) + + receivedContent := receivedPage.GetRawData() + require.NotNil(t, receivedContent) +} diff --git a/ruby/lib/gitaly_server/utils.rb b/ruby/lib/gitaly_server/utils.rb index 1d0bd89f0..31560adc8 100644 --- a/ruby/lib/gitaly_server/utils.rb +++ b/ruby/lib/gitaly_server/utils.rb @@ -57,7 +57,7 @@ module GitalyServer def gitaly_trailers_from_rugged(rugged_commit) rugged_commit.trailers.map do |(key, value)| - Gitaly::CommitTrailer.new(key: key, value: value) + Gitaly::CommitTrailer.new(key: key.b, value: value.b) end end |