mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 06:53:45 +08:00
FIX: Don’t raise an error on permalinks with external URL
Currently redirecting to an external URL through a permalink doesn’t work because Rails raises a `ActionController::Redirecting::UnsafeRedirectError` error. This wasn’t the case before we upgraded to Rails 7.0. This patch fixes the issue by using `allow_other_host: true` on the redirect.
This commit is contained in:
parent
b9ade92856
commit
a442eeb0f4
|
@ -11,7 +11,7 @@ class PermalinksController < ApplicationController
|
|||
raise Discourse::NotFound unless permalink
|
||||
|
||||
if permalink.target_url
|
||||
redirect_to permalink.target_url, status: :moved_permanently
|
||||
redirect_to permalink.target_url, status: :moved_permanently, allow_other_host: true
|
||||
else
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
|
|
|
@ -44,5 +44,14 @@ RSpec.describe PermalinksController do
|
|||
get "/not/a/valid/url"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
context "when permalink's target_url is an external URL" do
|
||||
before { permalink.update!(external_url: "https://github.com/discourse/discourse") }
|
||||
|
||||
it "redirects to it properly" do
|
||||
get "/#{permalink.url}"
|
||||
expect(response).to redirect_to(permalink.external_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user