Commit 85c20160 authored by Winnie Hellmann's avatar Winnie Hellmann

Merge branch 'tc-page-title-encoding-fix' into 'master'

URI decode Page-Title header to preserve UTF-8 characters

Closes #39179

See merge request gitlab-org/gitlab-ce!14929
parents f3117e79 d8d7faf6
......@@ -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;
......
......@@ -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
......@@ -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 }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment