diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-12-21 14:13:22 +0000 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-12-21 14:13:22 +0000 |
commit | b17e88dc685e3bb0284aa53ef933c02b1e8b199e (patch) | |
tree | d257714320e4cc1d2accc843a0b36921f4fd889b | |
parent | 9f1fe3ca49298c5ea52cd6ebb7c2e518d45e7718 (diff) |
Don't generate endlessly recursive URLs from request pages where the URL has a query string. Fixes #311.
-rwxr-xr-x | app/helpers/link_to_helper.rb | 11 | ||||
-rw-r--r-- | app/views/layouts/default.rhtml | 2 | ||||
-rw-r--r-- | spec/integration/view_request_spec.rb | 32 |
3 files changed, 42 insertions, 3 deletions
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 54b8d69d0..5866c31f0 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -185,9 +185,16 @@ module LinkToHelper end - def main_url(relative_path) + def main_url(relative_path, append = nil) url_prefix = "http://" + MySociety::Config.get("DOMAIN", '127.0.0.1:3000') - return url_prefix + relative_path + url = url_prefix + relative_path + if !append.nil? + env = Rack::MockRequest.env_for(url) + req = Rack::Request.new(env) + req.path_info += append + url = req.url + end + return url end # Basic date format diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml index 675bb38de..2f8e0bf36 100644 --- a/app/views/layouts/default.rhtml +++ b/app/views/layouts/default.rhtml @@ -49,7 +49,7 @@ <% end %> <% end %> <% if @has_json %> - <link rel="alternate" type="application/json" title="JSON version of this page" href="<%=h main_url(request.request_uri) %>.json"> + <link rel="alternate" type="application/json" title="JSON version of this page" href="<%=h main_url(request.request_uri, '.json') %>"> <% end %> <% if @no_crawl %> diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb new file mode 100644 index 000000000..cf1e4ca6c --- /dev/null +++ b/spec/integration/view_request_spec.rb @@ -0,0 +1,32 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "When viewing requests" do + + fixtures [ + :users, + :public_bodies, + :public_body_translations, + :public_body_versions, + :info_requests, + :raw_emails, + :outgoing_messages, + :incoming_messages, + :comments, + :info_request_events, + :track_things, + ] + + before(:each) do + emails = raw_emails.clone + load_raw_emails_data(emails) + end + + it "should not make endlessly recursive JSON <link>s" do + @dog_request = info_requests(:fancy_dog_request) + get "request/#{@dog_request.url_title}?unfold=1" + response.body.should_not include("dog?unfold=1.json") + response.body.should include("dog.json?unfold=1") + end + +end + |