A platform for community discussion. Free, open, simple.
FIX: permalink redirects with subfolder
Neil Lalonde2c4d7225d883
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex d5adf6ee1a0..79371c9423a 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -224,13 +224,8 @@ class ApplicationController < ActionController::Baseif permalink.present?# permalink present, redirect to that URL- if permalink.external_url- redirect_with_client_support permalink.external_url, status: :moved_permanently- return- elsif permalink.target_url- redirect_with_client_support "#{Discourse::base_uri}#{permalink.target_url}", status: :moved_permanently- return- end+ redirect_with_client_support permalink.target_url, status: :moved_permanently+ returnendenddiff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rbindex 5ad3aa60993..957607236d5 100644--- a/spec/requests/application_controller_spec.rb+++ b/spec/requests/application_controller_spec.rb@@ -37,6 +37,34 @@ RSpec.describe ApplicationController doexpect(response.body).to eq(external_url)end+ it 'supports subfolder with permalinks' do+ GlobalSetting.stubs(:relative_url_root).returns('/forum')+ Discourse.stubs(:base_uri).returns("/forum")++ trashed_topic = create_post.topic+ trashed_topic.trash!+ new_topic = create_post.topic+ permalink = Permalink.create!(url: trashed_topic.relative_url, topic_id: new_topic.id)++ # no subfolder because router doesn't know about subfolder in this test+ get "/t/#{trashed_topic.slug}/#{trashed_topic.id}"+ expect(response.status).to eq(301)+ expect(response).to redirect_to("/forum/t/#{new_topic.slug}/#{new_topic.id}")++ permalink.destroy+ category = Fabricate(:category)+ permalink = Permalink.create!(url: trashed_topic.relative_url, category_id: category.id)+ get "/t/#{trashed_topic.slug}/#{trashed_topic.id}"+ expect(response.status).to eq(301)+ expect(response).to redirect_to("/forum/c/#{category.slug}")++ permalink.destroy+ permalink = Permalink.create!(url: trashed_topic.relative_url, post_id: new_topic.posts.last.id)+ get "/t/#{trashed_topic.slug}/#{trashed_topic.id}"+ expect(response.status).to eq(301)+ expect(response).to redirect_to("/forum/t/#{new_topic.slug}/#{new_topic.id}/#{new_topic.posts.last.post_number}")+ end+it 'should return 404 and show Google search' doget "/t/nope-nope/99999999"expect(response.status).to eq(404)