Skip to content

Commit

Permalink
FHIR::Model.search method URI Encodes twice
Browse files Browse the repository at this point in the history
* Addresses including search parameters such as '>2016-01-01' get
  encoded twice, resulting in '%253E2016-01-01' instead of
  '%3E2016-01-01'
* Utilize the already-included Addressable gem to ensure that the URL is
  safe. This method was already use by the 'search' method, via
  'resource_url'. Running it through twice seems to be safe.
* Add a test to ensure that our search parameters get passed safely
  through search.
* Tests add WebMock, which allows us to run tests against fake data
  easily. This lets us verify the URL we attempted to use with little
  effort.
  • Loading branch information
wesrich committed Sep 28, 2016
1 parent 15e3d4e commit fd548d4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions fhir_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'pry'
s.add_development_dependency 'minitest'
s.add_development_dependency 'test-unit'
s.add_development_dependency 'webmock'
end
2 changes: 1 addition & 1 deletion lib/client_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def scrubbed_response_headers(result)
end

def get(path, headers)
url = URI(URI.escape(build_url(path))).to_s
url = Addressable::URI.parse(build_url(path)).to_s
FHIR.logger.info "GETTING: #{url}"
headers = clean_headers(headers)
if @use_oauth2_auth
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require 'pry'
require 'minitest/autorun'
require 'webmock/test_unit'
require 'bundler/setup'
require 'test/unit'
require 'turn'
1 change: 1 addition & 0 deletions test/unit/basic_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative '../test_helper'
WebMock.allow_net_connect!

class BasicTest < Test::Unit::TestCase

Expand Down
24 changes: 24 additions & 0 deletions test/unit/client_interface_sections/search_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require_relative '../../test_helper'

class ClientInterfaceSearchTest < Test::Unit::TestCase
def client
@client ||= FHIR::Client.new("feed-test")
end

def test_url_encoding_only_happens_once
stub_request(:get, /feed-test/)
reply = client.search(
FHIR::Appointment,
{
search: {
parameters: {
'patient' => 'test',
'date' => '>2016-01-01'
}
}
}
)
assert_equal 'feed-test/Appointment?date=%3E2016-01-01&patient=test',
reply.request[:url]
end
end

0 comments on commit fd548d4

Please sign in to comment.