URI decode Page-Title header to preserve UTF-8 characters
This commit is contained in:
parent
f3117e795d
commit
d8d7faf68c
3 changed files with 16 additions and 2 deletions
|
@ -95,7 +95,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']);
|
||||||
if (response.headers && response.headers['is-root'] && !Store.isInitialRoot) {
|
if (response.headers && response.headers['is-root'] && !Store.isInitialRoot) {
|
||||||
Store.isRoot = convertPermissionToBoolean(response.headers['is-root']);
|
Store.isRoot = convertPermissionToBoolean(response.headers['is-root']);
|
||||||
Store.isInitialRoot = Store.isRoot;
|
Store.isInitialRoot = Store.isRoot;
|
||||||
|
|
|
@ -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
|
||||||
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 }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue