Skip to content
Snippets Groups Projects
Commit af700c81 authored by Stan Hu's avatar Stan Hu
Browse files

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 gitlab-org/gitlab#301154
parent e8596a35
No related branches found
No related tags found
1 merge request!3169[13.8] Fix 500 errors in Wiki pages with trailers containing UTF-8
---
title: Fix 500 errors in Wiki pages with trailers containing UTF-8
merge_request: 3169
author:
type: fixed
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)
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment