Permalink
Browse files

Fix HTTPInteraction filtering to handle integers (e.g. port) correctly.

Previously, we would get an error:
  TypeError: can't convert Fixnum into String

Closes #167.
  • Loading branch information...
1 parent 8575ba5 commit 04cd2433bfca8281e7596924d17337821e795aac @myronmarston committed May 23, 2012
Showing with 12 additions and 3 deletions.
  1. +2 −0 CHANGELOG.md
  2. +4 −3 lib/vcr/structs.rb
  3. +6 −0 spec/vcr/structs_spec.rb
View
@@ -20,6 +20,8 @@
`WebMock.net_connect_allowed?` with arguments. Thanks to
[Gordon Wilson](https://github.com/gordoncww) for reporting the bug and
providing a fix.
+* Fix `filter_sensitive_data`/`define_cassette_placeholder` so that they
+ handle non-strings gracefully (e.g. the port number as a Fixnum).
## 2.1.1 (April 24, 2012)
View
@@ -502,10 +502,11 @@ def ignored?
# Replaces a string in any part of the HTTP interaction (headers, request body,
# response body, etc) with the given replacement text.
#
- # @param [String] text the text to replace
- # @param [String] replacement_text the text to put in its place
+ # @param [#to_s] text the text to replace
+ # @param [#to_s] replacement_text the text to put in its place
def filter!(text, replacement_text)
- return self if [text, replacement_text].any? { |t| t.to_s.empty? }
+ text, replacement_text = text.to_s, replacement_text.to_s
+ return self if [text, replacement_text].any? { |t| t.empty? }
filter_object!(self, text, replacement_text)
end
View
@@ -354,6 +354,12 @@ def assert_yielded_keys(hash, *keys)
it 'replaces sensitive text in the request URI' do
filtered.request.uri.should eq('http://example-AAA.com/AAA/')
end
+
+ it 'handles numbers (such as the port) properly' do
+ request.uri = "http://foo.com:9000/bar"
+ subject.filter!(9000, "<PORT>")
+ request.uri.should eq("http://foo.com:<PORT>/bar")
+ end
end
end

0 comments on commit 04cd243

Please sign in to comment.