Skip to content

Commit

Permalink
Remove trailing slashes from relative_url_root
Browse files Browse the repository at this point in the history
Rails.configuration.relative_url_root can be set to `/` and the prefix
cleanup will fail because because the prefix is now `//assets` instead
of `/assets`
  • Loading branch information
Marius Bobin committed May 19, 2020
1 parent c683fb6 commit 1a383b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/premailer/rails/css_loaders/asset_pipeline_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def load(url)

def file_name(url)
prefix = [
::Rails.configuration.relative_url_root,
::Rails.configuration.relative_url_root&.chomp('/'),
::Rails.configuration.assets.prefix,
'/'
].join
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/css_loaders/asset_pipeline_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
it { is_expected.to eq('application.css') }
end

context "when asset file path contains prefix and relative_url_root is set to root" do
before do
allow(Rails.configuration)
.to receive(:relative_url_root).and_return('/')
end

let(:asset) { '/assets/application.css' }
it { is_expected.to eq('application.css') }
end

context "when asset file path contains 32 chars fingerprint" do
let(:asset) { 'application-6776f581a4329e299531e1d52aa59832.css' }
it { is_expected.to eq('application.css') }
Expand Down

0 comments on commit 1a383b0

Please sign in to comment.