Wednesday, October 7, 2009

Fixing soap4r for ruby 1.9

soap4r 1.5.8 is broken on ruby 1.9, below are the steps I took to fix it. Please note I have not attempted to fix soap4r completely, and that this fix does not go beyond the purposes of my usage, there are likely to be areas that are still broken under 1.9.

lib/soap/baseData.rb

replace
TypeParseRegexp = Regexp.new('^(.+)\[([\d,]*)\]$', nil, 'NONE')

with
TypeParseRegexp = Regexp.new('^(.+)\[([\d,]*)\]$')

lib/soap/generator.rb

replace
Regexp.new("[#{EncodeMap.keys.join}]", nil, XSD::Charset.encoding)

with
Regexp.new("[#{EncodeMap.keys.join}]")

lib/soap/property.rb

replace
COMMENT_REGEXP = Regexp.new('^(?:#.*|)$', nil, 'u')
CATDEF_REGEXP = Regexp.new("^\\[\\s*#{KEY_REGSRC}\\s*\\]$", nil, 'u')
LINE_REGEXP = Regexp.new("^#{DEF_REGSRC}$", nil, 'u')

with
COMMENT_REGEXP = Regexp.new("^(?:#.*|)$")
CATDEF_REGEXP = Regexp.new("^\\[\\s*#{KEY_REGSRC}\\s*\\]$")
LINE_REGEXP = Regexp.new("^#{DEF_REGSRC}$")

remove / comment out
# for ruby/1.6.
unless Enumerable.instance_methods.include?('inject')
  module Enumerable
    def inject(init)
      result = init
      each do |item|
       result = yield(result, item)
      end
      result
    end
  end
end

lib/soap/rpc/element.rb

replace
type_qname = TypeMap.index(mapped_class)

with
type_qname = TypeMap.key(mapped_class)

lib/xsd/charset.rb

replace
@internal_encoding = $KCODE

with
@internal_encoding = "UTF8"

replace
USASCIIRegexp = Regexp.new("\\A#{us_ascii}*\\z", nil, 'NONE')

with
USASCIIRegexp = Regexp.new("\\A#{us_ascii}*\\z")

replace
EUCRegexp = Regexp.new("\\A#{character_euc}*\\z", nil, 'NONE')

with
EUCRegexp = Regexp.new("\\A#{character_euc}*\\z", nil, 'n')

replace
SJISRegexp = Regexp.new("\\A#{character_sjis}*\\z", nil, 'NONE')

with
SJISRegexp = Regexp.new("\\A#{character_sjis}*\\z", nil, 'n')

replace
character_utf8 =
"(?:#{us_ascii}|#{twobytes_utf8}|#{threebytes_utf8}|#{fourbytes_utf8})"
UTF8Regexp = Regexp.new("\\A#{character_utf8}*\\z", nil, 'NONE')

with
character_utf8 = "(?:#{us_ascii}|#{twobytes_utf8}|#{threebytes_utf8}|#{fourbytes_utf8})"
UTF8Regexp = Regexp.new("\\A#{character_utf8}*\\z", nil, 'n')

lib/xsd/ns.rb

replace
ParseRegexp = Regexp.new('\A([^:]+)(?::(.+))?\z', nil, 'NONE')

with
ParseRegexp = Regexp.new('\A([^:]+)(?::(.+))?\z')

lib/xsd/xmlparser.rb

replace
NSParseRegexp = Regexp.new('^xmlns:?(.*)$', nil, 'NONE')

with
NSParseRegexp = Regexp.new("^xmlns:?(.*)$")

replace
raise LoadError unless XSD::XMLParser.constants.find { |c| c.downcase == name }

with
raise LoadError unless XSD::XMLParser.constants.find { |c| c.to_s.downcase == name.downcase }

5 comments: