Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing mapping of symbol #13

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
24 changes: 16 additions & 8 deletions lib/soap/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def encode_data(ns, obj, parent)
add_reftarget(obj.elename.name, obj)
ref = SOAPReference.new(obj)
ref.elename = ref.elename.dup_name(obj.elename.name)
obj.precedents.clear # Avoid cyclic delay.
obj.precedents.clear # Avoid cyclic delay.
obj.encodingstyle = parent.encodingstyle
# SOAPReference is encoded here.
obj = ref
Expand Down Expand Up @@ -134,9 +134,9 @@ def encode_element(ns, obj, parent)
if obj.is_a?(SOAPBody)
@reftarget = obj
obj.encode(self, ns, attrs) do |child|
indent_backup, @indent = @indent, @indent + @indentstr
indent_backup, @indent = @indent, @indent + @indentstr
encode_data(ns.clone_ns, child, obj)
@indent = indent_backup
@indent = indent_backup
end
@reftarget = nil
else
Expand All @@ -145,9 +145,9 @@ def encode_element(ns, obj, parent)
Generator.assign_ns(attrs, ns, XSD::Namespace)
end
obj.encode(self, ns, attrs) do |child|
indent_backup, @indent = @indent, @indent + @indentstr
indent_backup, @indent = @indent, @indent + @indentstr
encode_data(ns.clone_ns, child, obj)
@indent = indent_backup
@indent = indent_backup
end
end
end
Expand Down Expand Up @@ -176,7 +176,7 @@ def encode_name_end(ns, data)
def encode_tag(elename, attrs = nil)
if attrs.nil? or attrs.empty?
@buf << "\n#{ @indent }<#{ elename }>"
return
return
end
ary = []
attrs.each do |key, value|
Expand All @@ -190,7 +190,7 @@ def encode_tag(elename, attrs = nil)
else
@buf << "\n#{ @indent }<#{ elename } " <<
ary.join("\n#{ @indent }#{ @indentstr * 2 }") <<
'>'
'>'
end
end

Expand Down Expand Up @@ -264,10 +264,18 @@ def get_encoded(str)
end
}.join
else
str.gsub(@encode_char_regexp) { |c| EncodeMap[c] }
safe_encode(str).gsub(@encode_char_regexp) { |c| EncodeMap[c] }
end
end

def safe_encode(str)
return '' if str.nil? || str.strip == ''
str.encode("ISO-8859-1").encode("UTF-8")
rescue => e
str = str.gsub(e.error_char, "")
safe_encode(str)
end

def get_encode_char_regexp
ENCODE_CHAR_REGEXP[XSD::Charset.encoding] ||=
Regexp.new("[#{EncodeMap.keys.join}]")
Expand Down
2 changes: 2 additions & 0 deletions lib/soap/mapping/encodedregistry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def find_mapped_obj_class(target_soap_class)
[::FalseClass, ::SOAP::SOAPBoolean, BasetypeFactory],
[::String, ::SOAP::SOAPString, StringFactory,
{:derived_class => true}],
[::Symbol, ::SOAP::SOAPString, StringFactory,
{:derived_class => true}],
[::DateTime, ::SOAP::SOAPDateTime, DateTimeFactory],
[::Date, ::SOAP::SOAPDate, DateTimeFactory],
[::Time, ::SOAP::SOAPDateTime, DateTimeFactory],
Expand Down