Skip to content

Commit

Permalink
fix(lib/string_tools) return nil if InvalidURIError
Browse files Browse the repository at this point in the history
  • Loading branch information
GIGrave committed Jan 14, 2016
1 parent 384b057 commit 84856d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
/spec/reports/
/tmp/
/gemfiles
/.idea
Makefile.local
2 changes: 2 additions & 0 deletions lib/string_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def add_params_to_url(url, params = nil)
uri = Addressable::URI.parse("http://#{url}") unless uri.scheme
uri.query_values = (uri.query_values || {}).merge!(params.stringify_keys) if params.present?
uri.normalize.to_s
rescue Addressable::URI::InvalidURIError
nil
end
end
extend Uri
Expand Down
8 changes: 8 additions & 0 deletions spec/string_tools_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,13 @@

it { expect(described_class.add_params_to_url(url, a: 'c')).to eq 'http://test.com/?a=c' }
end

context 'when empty url' do
let(:url) { '' }

it 'return nil' do
expect(described_class.add_params_to_url(url, a: 'b')).to be_nil
end
end
end
end

0 comments on commit 84856d8

Please sign in to comment.