# Weird string problem

**URL:** <https://www.ruby-forum.com/t/weird-string-problem/66618>\
**Category:** Ruby\
**Created:** [August 27, 2006, 10:59pm UTC](https://www.ruby-forum.com/t/weird-string-problem/66618 "2006-08-27T22:59:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_CSVerhage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ea924/32.png) [@Peter\_CSVerhage](https://www.ruby-forum.com/u/Peter_CSVerhage)\
**Post date:** [August 27, 2006, 10:59pm UTC](https://www.ruby-forum.com/t/weird-string-problem/66618/1 "2006-08-27T22:59:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Peter\_CSVerhage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ea924/32.png) [@Peter\_CSVerhage](https://www.ruby-forum.com/u/Peter_CSVerhage)\
**Post date:** [August 27, 2006, 11:05pm UTC](https://www.ruby-forum.com/t/weird-string-problem/66618/2 "2006-08-27T23:05:24Z")

</div>

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.  
>   
> 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?

---

<div class="post-metadata">

**Author:** ![Peter\_CSVerhage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ea924/32.png) [@Peter\_CSVerhage](https://www.ruby-forum.com/u/Peter_CSVerhage)\
**Post date:** [August 28, 2006, 1:07am UTC](https://www.ruby-forum.com/t/weird-string-problem/66618/3 "2006-08-28T01:07:27Z")

</div>

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

> > If I reassign the value of the structure attribute using:  
> > 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?

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

a=“string”.taint  
“#{a}”.tainted?  
==\> true

–Ken

---

<div class="post-metadata">

**Author:** ![Peter\_CSVerhage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ea924/32.png) [@Peter\_CSVerhage](https://www.ruby-forum.com/u/Peter_CSVerhage)\
**Post date:** [August 27, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/weird-string-problem/66618/4 "2006-08-27T23:17:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Peter\_CSVerhage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ea924/32.png) [@Peter\_CSVerhage](https://www.ruby-forum.com/u/Peter_CSVerhage)\
**Post date:** [August 29, 2006, 11:40pm UTC](https://www.ruby-forum.com/t/weird-string-problem/66618/5 "2006-08-29T23:40:55Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hi,

Sorry for late reply.

Peter C. Verhage wrote:

> 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

 blah blah 

instead of

epointment#1481

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  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2.1 (Cygwin)

iQEVAwUBRPS0Cx9L2jg5EEGlAQKUBwf/TlcHYFxCKypEV2600pFNdDpYji4aOaP6  
os/EfjQO+Vtk3Db75s86L6uGFO/XmUF+n7yq2Vvuo+3abgQS7aXIWMukl7FKghcu  
8FkAGdB+WDtTcy0fBNBHn85+xDKOjcVH5YBf/vbD/vin+Ad+4T4unBcRoT4HVyjM  
0Jle+2tZcJIq09buKc2Hn4SmiXrPzwkAqr326M445NxNkPtEeT+0Z09glnHdZDmp  
Uky1pJQkKa1Bq6d1mGo+eGFzs1eoeOjyCXMoq/pRZVJzmUxw9lpPxLfxI4qC1LdW  
l0P++ZZa1XaT87P9bUnzoZeYrl5Xe9TRtSZobU0ixoKb3uy9rNTIlw==  
=aBHq  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![Peter\_CSVerhage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ea924/32.png) [@Peter\_CSVerhage](https://www.ruby-forum.com/u/Peter_CSVerhage)\
**Post date:** [August 31, 2006, 12:51pm UTC](https://www.ruby-forum.com/t/weird-string-problem/66618/6 "2006-08-31T12:51:28Z")

</div>

NAKAMURA, Hiroshi wrote:

> 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
