diff options
-rwxr-xr-x | app/helpers/link_to_helper.rb | 12 | ||||
-rw-r--r-- | config/test.yml | 2 | ||||
-rw-r--r-- | spec/helpers/link_to_helper_spec.rb | 12 |
3 files changed, 21 insertions, 5 deletions
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 diff --git a/config/test.yml b/config/test.yml index e9e0aebfd..693cdd6b8 100644 --- a/config/test.yml +++ b/config/test.yml @@ -10,7 +10,7 @@ SITE_NAME: 'Alaveteli' # Domain used in URLs generated by scripts (e.g. for going in some emails) -DOMAIN: 'localhost:3000' +DOMAIN: 'test.localdomain' # ISO country code of country currrently deployed in # (http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index aae00c298..f85d2e70d 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -20,5 +20,17 @@ describe LinkToHelper do end end + + describe "when appending something to a URL" do + it 'should append to things without query strings' do + main_url('/a', '.json').should == 'http://test.localdomain/a.json' + end + it 'should append to things with query strings' do + main_url('/a?z=1', '.json').should == 'http://test.localdomain/a.json?z=1' + end + it 'should fail silently with invalid URLs' do + main_url('/a?z=9%', '.json').should == 'http://test.localdomain/a?z=9%' + end + end end |