Skip to content

Commit

Permalink
fix for issue 234
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed Oct 23, 2011
1 parent ba3abcc commit f9cf25b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
end
```

* Feature: Added an option to change the default encoding of the XML directive tag (defaults to UTF-8)
to fix [issue 234](https://github.com/rubiii/savon/issues/234).

``` ruby
client.request(:find_user) do
soap.encoding = "UTF-16"
soap.body = { :id => 1 }
end
```

* Improvement: Merged [pull request 231](https://github.com/rubiii/savon/pull/231) to gracefully handle
invalid response bodies by throwing a `Savon::SOAP::InvalidResponseError`.

Expand Down
10 changes: 9 additions & 1 deletion lib/savon/soap/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ def element_form_default
# Accessor for the <tt>Savon::WSSE</tt> object.
attr_accessor :wsse

# Returns the SOAP request encoding. Defaults to "UTF-8".
def encoding
@encoding ||= "UTF-8"
end

# Sets the SOAP request encoding.
attr_writer :encoding

# Accepts a +block+ and yields a <tt>Builder::XmlMarkup</tt> object to let you create
# custom body XML.
def body
Expand Down Expand Up @@ -161,7 +169,7 @@ def to_xml
private

# Returns a new <tt>Builder::XmlMarkup</tt> object.
def builder(directive_tag = :xml, attrs = {})
def builder(directive_tag = :xml, attrs = { :encoding => encoding })
builder = Builder::XmlMarkup.new
builder.instruct!(directive_tag, attrs) if directive_tag
builder
Expand Down
17 changes: 17 additions & 0 deletions spec/savon/soap/xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@
end
end

describe "#encoding" do
it "defaults to UTF-8" do
xml.encoding.should == "UTF-8"
end
end

describe "#xml" do
it "lets you specify a completely custom XML String" do
xml.xml = "<custom>xml</custom>"
Expand Down Expand Up @@ -190,6 +196,17 @@
end
end

context "with a custom encoding" do
after do
xml.encoding = nil
end

it "should change the default encoding" do
xml.encoding = "US-ASCII"
xml.to_xml.should match(/^<\?xml version="1.0" encoding="US-ASCII"\?>/)
end
end

context "with a SOAP header" do
it "should contain the given header" do
xml.header = {
Expand Down

0 comments on commit f9cf25b

Please sign in to comment.