Weird string problem

Hi,

I've got some weird string problem that in the end causes an error in SOAP4R / ActionWebService. I have a simple (SOAP) structure with some string attributes. The value assigned to this structure are read from a file. The structure itself is returned in an array by a SOAP method. This results in the following exception:

   Exception: Cannot map Array to SOAP/OM.

After some debugging I found out that this exception is caused by an earlier exception:

   Exception: Cannot map String to SOAP/OM.

After some more debugging I found out that the following string (and other strings read from the file on disk!) cause the exception:

   epointment#1481

Seems like an ordinary string to me. But when I print this string to the console, copy it and assign it directly to one of the attributes of the structure (instead of reading it from the file) the problem disappears.

If I reassign the value of the structure attribute using:

   obj.attr = "#{obj.attr}"

The problem also magically disappears.

When I compare the string from file and the string in my program using the following code:

   value = 'epointment#1481'
   p value == file_value # => true
   p value <=> file_value # => 0

They appear to be equal. I also checked if the string from file is frozen or not, but it isn't.

It might be some weird characterset problem, but if I look at the characters in the string they look like ordinary ASCII characters which are available in (all?) character sets. And even if they weren't why does my comparison return true then?

Does anybody have an idea what might be the problem here? And why SOAP4R might be choking on this?

Regards,

Peter

Peter C. Verhage wrote:

After some more debugging I found out that the following string (and
other strings read from the file on disk!) cause the exception:

   epointment#1481

Seems like an ordinary string to me. But when I print this string to the
console, copy it and assign it directly to one of the attributes of the
structure (instead of reading it from the file) the problem disappears.

If I reassign the value of the structure attribute using:

   obj.attr = "#{obj.attr}"

The problem also magically disappears.

<snip>

Does anybody have an idea what might be the problem here? And why SOAP4R
might be choking on this?

Regards,

Peter

I'm new to Ruby, so forgive me if I'm saying something ignorant, but...

You said you checked if it was frozen. Did you check if it was tainted?

···

--
Posted via http://www.ruby-forum.com/\.

Hi,

I finally found what is different from the string read from file and the string I manually created. The string from file has an added instance variable "@ical_params", which seems to be added by the ical library I'm using. The following check in SOAP4R (factory.rb) seems to be the problem:

class StringFactory_ < Factory
   ...

   def obj2soap(soap_class, obj, info, map)
     if !@allow_original_mapping and !obj.instance_variables.empty?
       return nil
     end
     ...

Removing this if-statement causes the problem to disappear. Now I just have to figure out why this if-statement is there and what it needs to do...

Regards,

Peter

Using #{} to include a string in another string should propagate taint.

a="string".taint
"#{a}".tainted?
==> true

--Ken

···

On Mon, 28 Aug 2006 06:05:29 +0900, William Crawford wrote:

Peter C. Verhage wrote:

After some more debugging I found out that the following string (and
other strings read from the file on disk!) cause the exception:

   epointment#1481

Seems like an ordinary string to me. But when I print this string to the
console, copy it and assign it directly to one of the attributes of the
structure (instead of reading it from the file) the problem disappears.

If I reassign the value of the structure attribute using:

   obj.attr = "#{obj.attr}"

The problem also magically disappears.

<snip>

Does anybody have an idea what might be the problem here? And why SOAP4R
might be choking on this?

Regards,

Peter

I'm new to Ruby, so forgive me if I'm saying something ignorant, but...

You said you checked if it was frozen. Did you check if it was tainted?

--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/

Hi,

Sorry for late reply.

Peter C. Verhage wrote:

Hi,

I finally found what is different from the string read from file and the
string I manually created. The string from file has an added instance
variable "@ical_params", which seems to be added by the ical library I'm
using. The following check in SOAP4R (factory.rb) seems to be the problem:

class StringFactory_ < Factory
  ...

  def obj2soap(soap_class, obj, info, map)
    if !@allow_original_mapping and !obj.instance_variables.empty?
      return nil
    end
    ...

Removing this if-statement causes the problem to disappear. Now I just
have to figure out why this if-statement is there and what it needs to
do...

Without this guard, soap4r will generate something like

  <epointment xsi:type="xsd:string">
    <ivars>
      <ical_params>blah blah</ical_params>
    </ivars>
  </epointment>

instead of

  <epointment xsi:type="xsd:string">epointment#1481</epointment>

which should not be what you want.

Hmm. Can soap4r distinguish objects

  class Foo
    attr_reader :ical_params
  end
  obj = Foo.new
  obj.ical_params = 123
  obj (ical_params in obj should be serialized)

and

  obj = "abc"
  obj.instance_eval { @ical_params = 123 }
  obj (ical_params in obj may not need to be serialized)

?

Regards,
// NaHi

NAKAMURA, Hiroshi wrote:

Hmm. Can soap4r distinguish objects

  class Foo
    attr_reader :ical_params
  end
  obj = Foo.new
  obj.ical_params = 123
  obj (ical_params in obj should be serialized)

and

  obj = "abc"
  obj.instance_eval { @ical_params = 123 }
  obj (ical_params in obj may not need to be serialized)

I don't think so. But can't this if statement simply return the string without the instance variables serialized instead of nil in case @allow_original_mapping is false?

Regards,

Peter