# Marshal erro with non ascii chars

**URL:** <https://www.ruby-forum.com/t/marshal-erro-with-non-ascii-chars/177975>\
**Category:** Ruby\
**Created:** [October 27, 2009, 12:55pm UTC](https://www.ruby-forum.com/t/marshal-erro-with-non-ascii-chars/177975 "2009-10-27T12:55:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelocavaco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@marcelocavaco](https://www.ruby-forum.com/u/marcelocavaco)\
**Post date:** [October 27, 2009, 12:55pm UTC](https://www.ruby-forum.com/t/marshal-erro-with-non-ascii-chars/177975/1 "2009-10-27T12:55:24Z")

</div>

first. sorry about my english. i dont speak english very well.

please, someone help me…

i have an array with 2 colums.

ex: myfiles[1] = name of file  
myfiles[2] = text of file

i used marshal.dump in this array.

later… i try use marshal.load

ex:

line 1 - scbase = File.open(source, ‘rb’) { |f| Marshal.load f }  
line 2 - scbase.each do |myfiles|  
line 3 - myfiles[1].gsub! ‘:’, ’ ’  
line 4 - path = folder + myfiles[1] + ‘.txt’  
line 5 - myfiles\_text = Zlib::Inflate.inflate(myfiles[2])  
line 6 - File.open(path, ‘wb’) {|file| file.write  
(myfiles\_text) }  
line 7 - end

if the second line of array contain a file name with non asciii char,  
the loop dont work.

when the line 4 is executed, the next loop is executed.

ex:

if the array contains 3 files:

1 = test  
2 = test \* number 2  
3 = another test

the line 2 is ignored and only 2 files is created.

but there is no error.

I thought to replace \* with \_ before the line 5.

but the loop is aborted before. in line 4.

any ideas?

please, help-me.

---

<div class="post-metadata">

**Author:** ![marcelocavaco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@marcelocavaco](https://www.ruby-forum.com/u/marcelocavaco)\
**Post date:** [October 27, 2009, 4:21pm UTC](https://www.ruby-forum.com/t/marshal-erro-with-non-ascii-chars/177975/2 "2009-10-27T16:21:16Z")

</div>

Marcelo C. wrote:

> if the second line of array contain a file name with non asciii char,  
> the loop dont work.
> 
> when the line 4 is executed, the next loop is executed.

Prove it or disprove it, by adding some printing. Here is a starting  
point:

> line 1 - scbase = File.open(source, ‘rb’) { |f| Marshal.load f }  
> STDERR.puts scbase.inspect  
> line 2 - scbase.each do |myfiles|  
> STDERR.puts “Processing #{myfiles.inspect}”  
> line 3 - myfiles[1].gsub! ‘:’, ’ ’  
> line 4 - path = folder + myfiles[1] + ‘.txt’  
> STDERR.puts “path = #{path.inspect}”  
> line 5 - myfiles\_text = Zlib::Inflate.inflate(myfiles[2])  
> STDERR.puts “read #{myfiles\_text.size} characters”  
> line 6 - File.open(path, ‘wb’) {|file| file.write  
> (myfiles\_text) }  
> STDERR.puts “written #{path.inspect}”  
> line 7 - end

As you find out exactly which lines are or are not being executed, then  
add further debugging.

> the line 2 is ignored and only 2 files is created.
> 
> but there is no error.

Seems unlikely. Loops don’t just silently restart, and you are not  
catching any exceptions.

One thought: what version of ruby are your running under?

Your example has a filename containing “\*”, but that is an ASCII char.  
If you really have non-ASCII characters, then ruby 1.9 may barf in  
unexpected ways. But this still doesn’t explain what you describe.

---

<div class="post-metadata">

**Author:** ![marcelocavaco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@marcelocavaco](https://www.ruby-forum.com/u/marcelocavaco)\
**Post date:** [October 28, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/marshal-erro-with-non-ascii-chars/177975/3 "2009-10-28T16:55:38Z")

</div>

First…

thank you for responding.

now,

my version is 1.8.6

and… sorry… i dont undertand very well…

obs: the “error” occurs with these characters also: à, ü, ñ, etc…

any code sugestion?

---

<div class="post-metadata">

**Author:** ![marcelocavaco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@marcelocavaco](https://www.ruby-forum.com/u/marcelocavaco)\
**Post date:** [October 28, 2009, 5:07pm UTC](https://www.ruby-forum.com/t/marshal-erro-with-non-ascii-chars/177975/4 "2009-10-28T17:07:42Z")

</div>

Marcelo C. wrote:

> my version is 1.8.6

OK, thanks.

> and… sorry… i dont undertand very well…

The question I was raising was: you said that your code fails when a  
line contains a non-ASCII character, but then you said that it fails on  
line 2 of the following input:

1 = test  
2 = test \* number 2  
3 = another test

but that’s just regular ASCII. So does it fail with both?

Anyway, the best way to get help is for you to make a small, completely  
standalone test program that demonstrates the issue - something which  
other people can run. Then they can hack at it to uncover where the  
problem lies.

> any code sugestion?

You could insert those STDERR.puts that I showed you into your code, run  
it again, watch it fail. Then you have some more info to work on.

I don’t believe your assertion that bits of your code are being silently  
skipped. I think something else is happening. I suspect the problem is  
to do with the bits of code that you _haven’t_ posted. Hence the  
importance of making a complete runnable program that demonstrates the  
issue.
