Merge branch 'fix/wiki-find-page-invalid-encoding' into 'master'

Fix finding wiki pages when they have invalidly-encoded content

Closes #43715

See merge request gitlab-org/gitlab-ce!18856
This commit is contained in:
Robert Speicher 2018-05-10 14:47:04 +00:00
commit f667bbceab
4 changed files with 31 additions and 1 deletions

View File

@ -1 +1 @@
0.99.0
0.100.0

View File

@ -0,0 +1,5 @@
---
title: Fix finding wiki pages when they have invalidly-encoded content
merge_request: 18856
author:
type: fixed

View File

@ -7,6 +7,20 @@ module Gollum
end
require "gollum-lib"
module Gollum
class Page
def text_data(encoding = nil)
data = if raw_data.respond_to?(:encoding)
raw_data.force_encoding(encoding || Encoding::UTF_8)
else
raw_data
end
Gitlab::EncodingHelper.encode!(data)
end
end
end
Rails.application.configure do
config.after_initialize do
Gollum::Page.per_page = Kaminari.config.default_per_page

View File

@ -159,6 +159,17 @@ describe ProjectWiki do
expect(page.title).to eq("autre pagé")
end
end
context 'pages with invalidly-encoded content' do
before do
create_page("encoding is fun", "f\xFCr".b)
end
it "can find the page" do
page = subject.find_page("encoding is fun")
expect(page.content).to eq("fr")
end
end
end
context 'when Gitaly wiki_find_page is enabled' do