summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-10-20 16:44:29 +0000
committerWinnie Hellmann <winnie@gitlab.com>2017-10-21 23:32:05 +0300
commitf846abdb665443e2f11fd39a74aa10ff0ee7cb34 (patch)
tree23ee391a12d181b2856414fcb1e776278bd1a283
parent0715fa63fdc53bb64844cbbb5695cce96f154dfa (diff)
downloadgitlab-ce-f846abdb665443e2f11fd39a74aa10ff0ee7cb34.tar.gz
URI decode Page-Title header to preserve UTF-8 characters
-rw-r--r--app/assets/javascripts/repo/helpers/repo_helper.js2
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--spec/controllers/application_controller_spec.rb14
3 files changed, 16 insertions, 2 deletions
diff --git a/app/assets/javascripts/repo/helpers/repo_helper.js b/app/assets/javascripts/repo/helpers/repo_helper.js
index 2d516fa5af2..f7b7f93e4b8 100644
--- a/app/assets/javascripts/repo/helpers/repo_helper.js
+++ b/app/assets/javascripts/repo/helpers/repo_helper.js
@@ -95,7 +95,7 @@ const RepoHelper = {
return Service.getContent()
.then((response) => {
const data = response.data;
- if (response.headers && response.headers['page-title']) data.pageTitle = response.headers['page-title'];
+ if (response.headers && response.headers['page-title']) data.pageTitle = decodeURI(response.headers['page-title']);
if (response.headers && response.headers['is-root'] && !Store.isInitialRoot) {
Store.isRoot = convertPermissionToBoolean(response.headers['is-root']);
Store.isInitialRoot = Store.isRoot;
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 967fe39256a..391a0519195 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -349,6 +349,6 @@ class ApplicationController < ActionController::Base
def set_page_title_header
# Per https://tools.ietf.org/html/rfc5987, headers need to be ISO-8859-1, not UTF-8
- response.headers['Page-Title'] = page_title('GitLab').encode('ISO-8859-1')
+ response.headers['Page-Title'] = URI.escape(page_title('GitLab'))
end
end
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 59a6cfbf4f5..0a3a0f7da18 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -221,6 +221,20 @@ describe ApplicationController do
end
end
+ describe '#set_page_title_header' do
+ let(:controller) { described_class.new }
+
+ it 'URI encodes UTF-8 characters in the title' do
+ response = double(headers: {})
+ allow_any_instance_of(PageLayoutHelper).to receive(:page_title).and_return('€100 · GitLab')
+ allow(controller).to receive(:response).and_return(response)
+
+ controller.send(:set_page_title_header)
+
+ expect(response.headers['Page-Title']).to eq('%E2%82%AC100%20%C2%B7%20GitLab')
+ end
+ end
+
context 'two-factor authentication' do
let(:controller) { described_class.new }