Skip to content

Commit

Permalink
Replace characters undefined in target encoding with empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
skorbut committed Jul 17, 2013
1 parent 6c44d59 commit b09f30b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/savon/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ def pretty

def to_s
return @locals[:xml] if @locals.include? :xml



string = tag(builder, :Envelope, namespaces_with_globals) do |xml|
tag(xml, :Header) { xml << header.to_s } unless header.empty?
tag(xml, :Body) { xml.tag!(*namespaced_message_tag) { xml << message.to_s } }
end

if @globals[:encoding] && @globals[:encode_message]
string.encode!(@globals[:encoding])
string.encode!(@globals[:encoding], undef: :replace, replace:'')
end
string
end
Expand Down
10 changes: 9 additions & 1 deletion spec/savon/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@
expect(builder.to_s.encoding.name).to eq "ISO-8859-1"
expect(builder.to_s).to include("<username>lüke</username>".encode("ISO-8859-1"))
end


it "ignores characters not found in the target encoding" do
globals[:encoding] = "ISO-8859-1"
globals[:encode_message] = true
locals[:message] = { :username => "lüke\u2122", :password => "secret" }
expect(builder.to_s.encoding.name).to eq "ISO-8859-1"
expect(builder.to_s).to include("<username>lüke</username>".encode("ISO-8859-1"))
end

context "with encode_message unset" do
before :each do
globals[:encoding] = "ISO-8859-1"
Expand Down

0 comments on commit b09f30b

Please sign in to comment.