From e7b2e867ff93b4d1daf04b829393ec7d50a27369 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 11 Jan 2012 09:24:36 +0000 Subject: Don't choke on unescaped characters in URIs. Fixes #335. --- app/helpers/link_to_helper.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app/helpers/link_to_helper.rb') diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 5866c31f0..7903dee2a 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -189,10 +189,14 @@ module LinkToHelper url_prefix = "http://" + MySociety::Config.get("DOMAIN", '127.0.0.1:3000') 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 + begin + env = Rack::MockRequest.env_for(url) + req = Rack::Request.new(env) + req.path_info += append + url = req.url + rescue URI::InvalidURIError + # don't append to it + end end return url end -- cgit v1.2.3 From 38010501139e051ab47f6142d75f0ac9af358093 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 25 Jan 2012 12:12:30 +0000 Subject: Simplify search logic so it doesn't depend on sessions. Also fixes #338 --- app/helpers/link_to_helper.rb | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'app/helpers/link_to_helper.rb') diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 7903dee2a..56c33e512 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -136,9 +136,19 @@ module LinkToHelper end # General pages. - def search_url(query, variety_postfix = nil, sort_postfix = nil, advanced = nil) - query = query - ["", nil] if query.kind_of?(Array) - url = search_general_url(:combined => query) + def search_url(query, params = nil) + if query.kind_of?(Array) + query = query - ["", nil] + query = query.join("/") + end + routing_info = {:controller => 'general', + :action => 'search', + :combined => query, + :view => nil} + if !params.nil? + routing_info = params.merge(routing_info) + end + url = url_for(routing_info) # Here we can't escape the slashes, as RFC 2396 doesn't allow slashes # within a path component. Rails is assuming when generating URLs that # either there aren't slashes, or we are in a query part where you can @@ -150,19 +160,10 @@ module LinkToHelper # http://rails.lighthouseapp.com/projects/8994/tickets/144-patch-bug-in-rails-route-globbing url = url.gsub("%2F", "/") - if !variety_postfix.nil? && !variety_postfix.empty? - url = url + "/" + variety_postfix - end - if !sort_postfix.nil? && !sort_postfix.empty? - url = url + "/" + sort_postfix - end - if !advanced.nil? && (advanced) - url = url + "/advanced" - end return url end def search_link(query, variety_postfix = nil, sort_postfix = nil, advanced = nil) - link_to h(query), search_url(query, variety_postfix, sort_postfix, advanced) + link_to h(query), search_url(query) end # Admin pages -- cgit v1.2.3