BigW Consortium Gitlab

Commit 1652288f by Winnie Hellmann

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

URI decode Page-Title header to preserve UTF-8 characters Closes #39179 (cherry-picked from 85c20160) See merge request gitlab-org/gitlab-ce!14929
parent a0fc7c48
...@@ -135,7 +135,7 @@ const RepoHelper = { ...@@ -135,7 +135,7 @@ const RepoHelper = {
return Service.getContent() return Service.getContent()
.then((response) => { .then((response) => {
const data = response.data; 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']);
Store.isTree = RepoHelper.isTree(data); Store.isTree = RepoHelper.isTree(data);
if (!Store.isTree) { if (!Store.isTree) {
......
...@@ -349,6 +349,6 @@ class ApplicationController < ActionController::Base ...@@ -349,6 +349,6 @@ class ApplicationController < ActionController::Base
def set_page_title_header def set_page_title_header
# Per https://tools.ietf.org/html/rfc5987, headers need to be ISO-8859-1, not UTF-8 # 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
end end
...@@ -221,6 +221,20 @@ describe ApplicationController do ...@@ -221,6 +221,20 @@ describe ApplicationController do
end end
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 context 'two-factor authentication' do
let(:controller) { described_class.new } 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