summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-06-30 12:12:16 -0700
committerStan Hu <stanhu@gmail.com>2016-07-01 09:10:12 -0700
commit4bfe10d5f972c64241cfdd0393d4d55a63092dc4 (patch)
tree802f991838cd46d5ee299cedbcc7260b71bb38aa
parent6c0d3b4cf3847b78b89170ccb0d8a1e5ebdc48d6 (diff)
downloadgitlab-ce-4bfe10d5f972c64241cfdd0393d4d55a63092dc4.tar.gz
Fix emoji paths in relative root configurations
If a site specifies a relative URL root, emoji files would omit the path from the URL, leading to lots of 404s. Closes #15642
-rw-r--r--lib/gitlab/award_emoji.rb11
-rw-r--r--spec/lib/gitlab/award_emoji_spec.rb15
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/gitlab/award_emoji.rb b/lib/gitlab/award_emoji.rb
index 51b1df9ecbd..c94bfc0e65f 100644
--- a/lib/gitlab/award_emoji.rb
+++ b/lib/gitlab/award_emoji.rb
@@ -66,8 +66,17 @@ module Gitlab
def self.urls
@urls ||= begin
path = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json')
+ # Construct the full asset path ourselves because
+ # ActionView::Helpers::AssetUrlHelper.asset_url is slow for hundreds
+ # of entries since it has to do a lot of extra work (e.g. regexps).
prefix = Gitlab::Application.config.assets.prefix
digest = Gitlab::Application.config.assets.digest
+ base =
+ if defined?(Gitlab::Application.config.relative_url_root) && Gitlab::Application.config.relative_url_root
+ Gitlab::Application.config.relative_url_root
+ else
+ ''
+ end
JSON.parse(File.read(path)).map do |hash|
if digest
@@ -76,7 +85,7 @@ module Gitlab
fname = hash['unicode']
end
- { name: hash['name'], path: "#{prefix}/#{fname}.png" }
+ { name: hash['name'], path: File.join(base, prefix, "#{fname}.png") }
end
end
end
diff --git a/spec/lib/gitlab/award_emoji_spec.rb b/spec/lib/gitlab/award_emoji_spec.rb
index 0f3852b1729..00a110e31f8 100644
--- a/spec/lib/gitlab/award_emoji_spec.rb
+++ b/spec/lib/gitlab/award_emoji_spec.rb
@@ -2,6 +2,10 @@ require 'spec_helper'
describe Gitlab::AwardEmoji do
describe '.urls' do
+ after do
+ Gitlab::AwardEmoji.instance_variable_set(:@urls, nil)
+ end
+
subject { Gitlab::AwardEmoji.urls }
it { is_expected.to be_an_instance_of(Array) }
@@ -15,6 +19,17 @@ describe Gitlab::AwardEmoji do
end
end
end
+
+ context 'handles relative root' do
+ it 'includes the full path' do
+ allow(Gitlab::Application.config).to receive(:relative_url_root).and_return('/gitlab')
+
+ subject.each do |hash|
+ expect(hash[:name]).to be_an_instance_of(String)
+ expect(hash[:path]).to start_with('/gitlab')
+ end
+ end
+ end
end
describe '.emoji_by_category' do