FIX: permalinks redirect on subfolder installs could add the subfolder to the url twice
This commit is contained in:
parent
1a3e9cf571
commit
3ef16a7711
|
@ -11,7 +11,7 @@ class PermalinksController < ApplicationController
|
|||
if permalink.external_url
|
||||
redirect_to permalink.external_url, status: :moved_permanently
|
||||
elsif permalink.target_url
|
||||
redirect_to "#{Discourse::base_uri}#{permalink.target_url}", status: :moved_permanently
|
||||
redirect_to permalink.target_url, status: :moved_permanently
|
||||
else
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
|
|
|
@ -75,7 +75,7 @@ class Permalink < ActiveRecord::Base
|
|||
|
||||
def target_url
|
||||
return external_url if external_url
|
||||
return post.url if post
|
||||
return "#{Discourse::base_uri}#{post.url}" if post
|
||||
return topic.relative_url if topic
|
||||
return category.url if category
|
||||
nil
|
||||
|
|
|
@ -10,6 +10,16 @@ describe PermalinksController do
|
|||
expect(response.status).to eq(301)
|
||||
end
|
||||
|
||||
it "should work for subfolder installs too" do
|
||||
GlobalSetting.stubs(:relative_url_root).returns('/forum')
|
||||
Discourse.stubs(:base_uri).returns("/forum")
|
||||
permalink = Fabricate(:permalink)
|
||||
Permalink.any_instance.stubs(:target_url).returns('/forum/t/the-topic-slug/42')
|
||||
get :show, url: permalink.url
|
||||
expect(response).to redirect_to('/forum/t/the-topic-slug/42')
|
||||
expect(response.status).to eq(301)
|
||||
end
|
||||
|
||||
it "should apply normalizations" do
|
||||
SiteSetting.permalink_normalizations = "/(.*)\\?.*/\\1"
|
||||
|
||||
|
|
Loading…
Reference in New Issue