Skip to content

A platform for community discussion. Free, open, simple.

FIX: handle invalid tags

Arpit Jalan9532d9a555a6
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 67c4ee54d36..d5c086d2ae2 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -277,10 +277,14 @@ class TagsController < ::ApplicationController
def construct_url_with(action, opts)
method = url_method(opts)
- url = if action == :prev
- public_send(method, opts.merge(prev_page_params(opts)))
- else # :next
- public_send(method, opts.merge(next_page_params(opts)))
+ begin
+ url = if action == :prev
+ public_send(method, opts.merge(prev_page_params(opts)))
+ else # :next
+ public_send(method, opts.merge(next_page_params(opts)))
+ end
+ rescue
+ raise Discourse::NotFound
end
url.sub('.json?', '?')
end
diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb
index 13a991ad8d3..65165852a98 100644
--- a/spec/requests/tags_controller_spec.rb
+++ b/spec/requests/tags_controller_spec.rb
@@ -50,6 +50,22 @@ describe TagsController do
end
end
+ describe '#show' do
+ before do
+ Fabricate(:tag, name: 'test')
+ end
+
+ it "should return the right response" do
+ get "/tags/test"
+ expect(response).to be_success
+ end
+
+ it "should handle invalid tags" do
+ get "/tags/%2ftest%2f"
+ expect(response.status).to eq(404)
+ end
+ end
+
describe '#check_hashtag' do
let(:tag) { Fabricate(:tag, name: 'test') }