FIX: Use absolute URL when redirecting SVG sprite path.

This ensures that CDN URLs with relative paths do not end up losing the
relative paths.
This commit is contained in:
Alan Guo Xiang Tan 2021-06-30 11:04:07 +08:00
parent e81a98ec94
commit 9a7adcd178
2 changed files with 13 additions and 4 deletions

View File

@ -12,10 +12,10 @@ class SvgSpriteController < ApplicationController
no_cookies
RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do
theme_id = params[:theme_id].to_i
theme_id = params[:theme_id].to_i if params[:theme_id].present?
if SvgSprite.version(theme_id) != params[:version]
return redirect_to path(SvgSprite.path(theme_id))
return redirect_to UrlHelper.absolute((SvgSprite.path(theme_id)))
end
svg_sprite = "window.__svg_sprite = #{SvgSprite.bundle(theme_id).inspect};"

View File

@ -24,8 +24,17 @@ describe SvgSpriteController do
random_hash = Digest::SHA1.hexdigest("somerandomstring")
get "/svg-sprite/#{Discourse.current_hostname}/svg--#{random_hash}.js"
expect(response.status).to eq(302)
expect(response.location).to include(SvgSprite.version)
expect(response).to redirect_to(
"/svg-sprite/test.localhost/svg--#{SvgSprite.version}.js"
)
set_cdn_url "//some-cdn.com/site"
get "/svg-sprite/#{Discourse.current_hostname}/svg--#{random_hash}.js"
expect(response).to redirect_to(
"https://some-cdn.com/site/svg-sprite/test.localhost/svg--#{SvgSprite.version}.js"
)
end
end