diff options
author | Robert Speicher <robert@gitlab.com> | 2018-05-10 14:47:04 +0000 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2018-05-10 11:39:49 -0500 |
commit | bd581a35c204444344b611cea33fbf6273feeaa8 (patch) | |
tree | f8c2ba14be41e182bb4d25c6c4162dfccf811944 | |
parent | 6657e65dd1470fdcb92870fcd9711fa220d1e0a5 (diff) | |
download | gitlab-ce-bd581a35c204444344b611cea33fbf6273feeaa8.tar.gz |
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
-rw-r--r-- | GITALY_SERVER_VERSION | 2 | ||||
-rw-r--r-- | changelogs/unreleased/fix-wiki-find-page-invalid-encoding.yml | 5 | ||||
-rw-r--r-- | config/initializers/gollum.rb | 14 | ||||
-rw-r--r-- | spec/models/project_wiki_spec.rb | 11 |
4 files changed, 31 insertions, 1 deletions
diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index 01781720cd4..897e21587ed 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -0.99.0 +0.100.0 diff --git a/changelogs/unreleased/fix-wiki-find-page-invalid-encoding.yml b/changelogs/unreleased/fix-wiki-find-page-invalid-encoding.yml new file mode 100644 index 00000000000..f003bef8671 --- /dev/null +++ b/changelogs/unreleased/fix-wiki-find-page-invalid-encoding.yml @@ -0,0 +1,5 @@ +--- +title: Fix finding wiki pages when they have invalidly-encoded content +merge_request: 18856 +author: +type: fixed diff --git a/config/initializers/gollum.rb b/config/initializers/gollum.rb index 81e0577a7c9..ea9cc151a57 100644 --- a/config/initializers/gollum.rb +++ b/config/initializers/gollum.rb @@ -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 diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index d6c4031329d..f1142832f1a 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -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 |