# SQLite3/Sinatra not returning results

**URL:** <https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313>\
**Category:** Ruby\
**Created:** [November 18, 2010, 12:19pm UTC](https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313 "2010-11-18T12:19:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [November 18, 2010, 12:19pm UTC](https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313/1 "2010-11-18T12:19:13Z")

</div>

Hi,

This has been doing my head in all morning - I wonder if anyone can help  
me work out where my problem is:

I have the following code within a Sinatra app:

$probe\_db\_file = “data/lumiHumanIDMapping.sqlite”  
$probe\_table = “HumanHT12\_V4\_0\_R2\_15002873\_B”  
$data\_db\_file = “data/rpediff.db”

$probe\_db = SQLite3::Database.new($probe\_db\_file)  
$data\_db = SQLite3::Database.new($data\_db\_file)

get ‘/:gene’ do |gene|

STDOUT.puts gene.inspect  
STDOUT.puts gene.class  
STDOUT.puts gene == “PAX6”

probes = $probe\_db.execute(“SELECT Probe\_ID,Symbol from  
#{$probe\_table}  
WHERE Symbol = ?”,gene).map{|row| row[0]}

STDOUT.puts “#{Time.now} - Gene: #{gene}”  
STDOUT.puts “#{Time.now} - Probes: #{probes.inspect}”

gene = “PAX6”

probes = $probe\_db.execute(“SELECT Probe\_ID,Symbol from  
#{$probe\_table}  
WHERE Symbol = ?”,gene).map{|row| row[0]}

STDOUT.puts “#{Time.now} - Gene: #{gene}”  
STDOUT.puts “#{Time.now} - Probes: #{probes.inspect}”

end

Running on my development machine (OSX, Ruby 1.8.7, Sinatra 1.1,  
sqlite3-ruby 1.3.2) this logs (as expected):

“PAX6”  
String  
true  
Thu Nov 18 11:12:09 +0000 2010 - Gene: PAX6  
Thu Nov 18 11:12:09 +0000 2010 - Probes: [“ILMN\_1789905”,  
“ILMN\_2314140”]  
Thu Nov 18 11:12:09 +0000 2010 - Gene: PAX6  
Thu Nov 18 11:12:09 +0000 2010 - Probes: [“ILMN\_1789905”,  
“ILMN\_2314140”]

Running on my production machine (Linux, Ruby 1.9.2, Sinatra 1.1,  
sqlite3-ruby 1.3.2) the same query logs:

“PAX6”  
String  
true  
2010-11-18 11:08:48 +0000 - Gene: PAX6  
2010-11-18 11:08:48 +0000 - Probes: []  
2010-11-18 11:08:48 +0000 - Gene: PAX6  
2010-11-18 11:08:48 +0000 - Probes: [“ILMN\_1789905”, “ILMN\_2314140”]

So on this machine the first query returns an empty result for some  
reason, even though the rows it should match _are_ in $probe\_table (as  
you  
can see I can find them if I set the ‘gene’ parameter ‘manually’). All I  
can think of is that somewhere in Sinatra/sqlite3-ruby the ‘gene’  
variable  
is not quite the simple String it claims to be, but the fact that this  
only  
seems to happen on Ruby 1.9.2 has got me baffled! Both Probe\_ID and  
Symbol  
are TEXT columns in Sqlite3 BTW.

---

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [November 25, 2010, 12:35pm UTC](https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313/2 "2010-11-25T12:35:11Z")

</div>

Hi Alex,

the problem is probably related to the different ruby versions since  
many things have changed between 1.8.7 and 1.9.2. Try installing ruby  
1.9.2 with RVM ( [http://rvm.beginrescueend.com](http://rvm.beginrescueend.com) ) on your development  
machine and see if you have the same problem.

$ gem install rvm  
$ rvm-install  
$ rvm install ruby-1.9.2  
$ rvm use --default ruby-1.9.2

Fix your .profile, make sure you don’t export GEM\_HOME in the  
environment and that ~/.gemrc  
doesn’t list “gem: --user-install”. Othewise, it works pretty well.

RVM is also able to switch ruby versions depending on the project you’re  
working on, which is handy if you have different projects which require  
different ruby versions.

Cheers,  
zimbatm

---

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [November 25, 2010, 1:15pm UTC](https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313/3 "2010-11-25T13:15:16Z")

</div>

On Thu, 25 Nov 2010 20:35:13 +0900, “zimbatm …” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> $ rvm use --default ruby-1.9.2  
> zimbatm  
> Thanks. It turned out to be an String encoding issue. Sinatra was  
> returning an “ASCII-8BIT” encoded string, while the SQLite3 db is  
> “US-ASCII” encoded. Manually setting the Sinatra string encoding to  
> “US-ASCII” got the DB query to match.

---

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [November 29, 2010, 12:39pm UTC](https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313/4 "2010-11-29T12:39:21Z")

</div>

Alex G. wrote in post #963848:

> On Thu, 25 Nov 2010 20:35:13 +0900, “zimbatm …” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > $ rvm use --default ruby-1.9.2  
> > zimbatm  
> > Thanks. It turned out to be an String encoding issue. Sinatra was  
> > returning an “ASCII-8BIT” encoded string, while the SQLite3 db is  
> > “US-ASCII” encoded. Manually setting the Sinatra string encoding to  
> > “US-ASCII” got the DB query to match.

Ergh. I can replicate this, with ruby 1.9.2p0 (rvm) + sqlite3-ruby-1.3.2  
(gem) under Ubuntu Lucid x86\_64.

ruby-1.9.2-p0 \> require ‘sqlite3’  
=\> true  
ruby-1.9.2-p0 \> db = SQLite3::Database.new(“foo.db”)  
=\> #SQLite3::Database:0x00000002631bc0  
ruby-1.9.2-p0 \> db.execute(“create table foo (id integer auto\_increment,  
bar varchar(255))”)  
=\>   
ruby-1.9.2-p0 \> db.execute(“insert into foo (bar) values (‘hello’)”)  
=\>   
ruby-1.9.2-p0 \> s1, s2, s3 = “hello”,  
“hello”.force\_encoding(“US-ASCII”), “hello”.force\_encoding(“ASCII-8BIT”)  
=\> [“hello”, “hello”, “hello”]  
ruby-1.9.2-p0 \> s1 == s2  
=\> true  
ruby-1.9.2-p0 \> s1 == s3  
=\> true  
ruby-1.9.2-p0 \> db.execute(“select \* from foo where bar=?”, s1)  
=\> [[nil, “hello”]]  
ruby-1.9.2-p0 \> db.execute(“select \* from foo where bar=?”, s2)  
=\> [[nil, “hello”]]  
ruby-1.9.2-p0 \> db.execute(“select \* from foo where bar=?”, s3)  
=\>

So s1 == s3, but the two queries give different results?? This is  
barking mad. Having said that, I can’t find anything in the sqlite3-ruby  
documentation which says how queries may be affected by encodings, so  
the behaviour is undefined.

Sinatra’s documentation also doesn’t seem to mention the encoding that  
your |gene| parameter will have, so you have to find out by  
trial-and-error that it’s ASCII-8BIT. You might have guessed this  
because the data comes from a socket and sockets get ASCII-8BIT by  
default - but Sinatra might have decided to parse the  
Content-Type:…encoding parameter and apply that.

In ruby 1.8 the value “hello” is just 5 bytes, with no hidden dimension  
to worry about.

---

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [March 28, 2011, 2:12am UTC](https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313/5 "2011-03-28T02:12:46Z")

</div>

> [http://redmine.ruby-lang.org/issues/show/4279](http://redmine.ruby-lang.org/issues/show/4279)  
> pack.c (pack\_unpack): the resulted string of unpack(‘M’) must have  
> ASCII-8BIT encoding (and ENC\_CODERANGE\_VALID). [ruby-core:34482]

Oops, that’s unpack(‘M’), Rack is using unpack(‘m’).

---

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [March 27, 2011, 11:15pm UTC](https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313/6 "2011-03-27T23:15:20Z")

</div>

Content preview: On 29.11.2010 12:39, Brian C. wrote: \> Ergh. I  
can replicate  
this, with ruby 1.9.2p0 (rvm) + sqlite3-ruby-1.3.2 \> (gem) under  
Ubuntu Lucid  
x86\_64. \> \> ruby-1.9.2-p0 \> require ‘sqlite3’ \> =\> true \>  
ruby-1.9.2-p0 \>  
db = SQLite3::Database.new(“foo.db”) \> =\>  
#SQLite3::Database:0x00000002631bc0  
\> ruby-1.9.2-p0 \> db.execute(“create table foo (id integer  
auto\_increment,  
\> bar varchar(255))”) \> =\> \> ruby-1.9.2-p0 \> db.execute(“insert  
into foo  
(bar) values (‘hello’)”) \> =\> \> ruby-1.9.2-p0 \> s1, s2, s3 =  
“hello”,

> “hello”.force\_encoding(“US-ASCII”),  
> “hello”.force\_encoding(“ASCII-8BIT”)  
> =\> [“hello”, “hello”, “hello”] \> ruby-1.9.2-p0 \> s1 == s2 \> =\>  
> true \> ruby-1.9.2-p0  
> s1 == s3 \> =\> true \> ruby-1.9.2-p0 \> db.execute(“select \* from foo  
> where  
> bar=?”, s1) \> =\> [[nil, “hello”]] \> ruby-1.9.2-p0 \>  
> db.execute(“select \*  
> from foo where bar=?”, s2) \> =\> [[nil, “hello”]] \> ruby-1.9.2-p0 \>  
> db.execute(“select  
> \* from foo where bar=?”, s3) \> =\> \> \> So s1 == s3, but the two  
> queries  
> give different results?? This is \> barking mad. Having said that, I  
> can’t  
> find anything in the sqlite3-ruby \> documentation which says how  
> queries  
> may be affected by encodings, so \> the behaviour is undefined. […]

Content analysis details: (-2.6 points, 5.0 required)

pts rule name description

* * *

* * *

-1.0 ALL\_TRUSTED Passed through trusted hosts only via SMTP  
-1.9 BAYES\_00 BODY: Bayes spam probability is 0 to 1%  
[score: 0.0000]  
0.0 T\_FILL\_THIS\_FORM\_SHORT Fill in a short form with personal  
information  
0.3 FILL\_THIS\_FORM\_FRAUD\_PHISH Answer suspicious question(s)  
X-Cloudmark-Analysis: v=1.1  
cv=kRmApA04uPli/d8B8u1M0swu98hronvs6VvAqI8uQP0= c=1 sm=0  
a=svAFAT5c7LwA:10 a=n5\_bRNUYKd4A:10 a=IkcTkHD0fZMA:10  
a=ifuZSf0M0LJmHL7QMhgA:9 a=5xJxjBpEekpQfdk-FI8A:7  
a=OicNPj6H6IkURmuq\_doO-2SJYXsA:4 a=QEXdDO2ut3YA:10  
a=HpAAvcLHHh0Zw7uRqdWCyQ==:117  
Mime-Version: 1.0  
Content-Type: text/plain; charset=UTF-8  
Content-Transfer-Encoding: 7bit  
Precedence: bulk  
Lines: 110  
List-Id: [ruby-talk.ruby-lang.org](http://ruby-talk.ruby-lang.org)  
List-Software: fml [fml 4.0.3 release (20011202/4.0.3)]  
List-Post: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
List-Owner: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
List-Help: [mailto:removed\_email\_address@domain.invalid?body=help](mailto:removed_email_address@domain.invalid?body=help)  
List-Unsubscribe: [mailto:removed\_email\_address@domain.invalid?body=unsubscribe](mailto:removed_email_address@domain.invalid?body=unsubscribe)  
Received-SPF: none (Address does not pass the Sender Policy Framework)  
SPF=FROM;  
[sender=removed\_email\_address@domain.invalid](mailto:sender=removed_email_address@domain.invalid);  
remoteip=::ffff:221.186.184.68;  
[remotehost=carbon.ruby-lang.org](http://remotehost=carbon.ruby-lang.org);  
[helo=carbon.ruby-lang.org](http://helo=carbon.ruby-lang.org);  
[receiver=eq4.andreas-s.net](http://receiver=eq4.andreas-s.net);

On 29.11.2010 12:39, Brian C. wrote:

> ruby-1.9.2-p0 \> db.execute(“insert into foo (bar) values (‘hello’)”)  
> ruby-1.9.2-p0 \> db.execute(“select \* from foo where bar=?”, s2)  
> =\> [[nil, “hello”]]  
> ruby-1.9.2-p0 \> db.execute(“select \* from foo where bar=?”, s3)  
> =\>
> 
> So s1 == s3, but the two queries give different results?? This is  
> barking mad. Having said that, I can’t find anything in the sqlite3-ruby  
> documentation which says how queries may be affected by encodings, so  
> the behaviour is undefined.

I was just affected by that, Brian, rhanks for analyzing this problem in  
the past! I’m running 1.9.2-p180 in my case. Now when I re-read the  
other thread "A question about Ruby 1.9’s “external encoding” when  
Robert concludes “The rule as such is pretty clear IMHO” and “Now,  
everything is clear” I feel like:

[nothing.is.clear.to.me](http://nothing.is.clear.to.me)

What is this whole character encoding madness about? I never encountered  
a language I stumbled into so many subtle problems with encodings left  
and right (mainly working with Java in my case). The more I work with  
ruby 1.9, the more confusing it gets. I’m getting worried. What am I  
missing what others do know that I run into such troubles?

Getting back to this specific case, where’s the problem exactly here? Is  
it Sinatra? My source file? The sqlite database?

I wrote a simple testing app for the sqlite db and got this:

$ sqlite3 database.sqlite3 .dump  
PRAGMA foreign\_keys=OFF;  
BEGIN TRANSACTION;  
CREATE TABLE user ( username varchar(255), password varchar(255), email  
varchar(255));  
INSERT INTO “user” VALUES(‘a’,‘b’,‘c’);  
COMMIT;

$ cat dbitest.rb  
require ‘dbi’  
require ‘pp’

dbi = DBI.connect(‘dbi:SQLite3:database.sqlite3’)

sql = “SELECT \* FROM user WHERE username = ? AND password = ?”

username = ‘a’  
password = ‘b’

pp username.encoding, password.encoding, dbi.select\_one(sql, username,  
password)[0].encoding

$ ruby dbitest.rb  
#Encoding:US-ASCII  
#Encoding:US-ASCII  
#Encoding:UTF-8

Within Sinatra it is as you said:

Relevant excerpt of the code:

if @auth.provided? && @auth.basic? && @auth.credentials  
sql = “SELECT \* FROM user WHERE username = ? AND password = ?”  
username = @auth.credentials[0]  
password = @auth.credentials[1]  
pp username.encoding, password.encoding, $dbi.select\_one(sql,  
username, password)  
username.force\_encoding(‘US-ASCII’)  
password.force\_encoding(‘US-ASCII’)  
pp username.encoding, password.encoding, $dbi.select\_one(sql,  
username, password)[0].encoding  
end

This is the output

#Encoding:ASCII-8BIT  
#Encoding:ASCII-8BIT  
nil  
#Encoding:US-ASCII  
#Encoding:US-ASCII  
#Encoding:UTF-8

Stunning.

- Markus

---

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [March 28, 2011, 2:11am UTC](https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313/7 "2011-03-28T02:11:28Z")

</div>

On Sun, Mar 27, 2011 at 5:14 PM, Markus F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> pp username.encoding, password.encoding, $dbi.select\_one(sql,  
> #Encoding:UTF-8  
> Getting back to this specific case, where’s the  
> problem exactly here? Is it Sinatra? My source  
> file? The sqlite database?

The credentials in Sinatra are unpacked in Rack:

ruby 1.9.2p0:

> Encoding.default\_external  
> =\> #Encoding:UTF-8  
> Encoding.default\_internal  
> =\> nil  
> s = ‘hello’  
> =\> “hello”  
> s.encoding  
> =\> #Encoding:UTF-8  
> [s].pack(‘m\*’)  
> =\> “aGVsbG8=\n”  
> [s].pack(‘m\*’).unpack(‘m\*’)  
> =\> [“hello”]  
> [s].pack(‘m\*’).unpack(‘m\*’).first.encoding  
> =\> #Encoding:ASCII-8BIT

rack/blob/master/lib/rack/auth/basic.rb:  
def credentials  
@credentials ||= params.unpack(“m\*”).first.split(/:/, 2)  
end

[http://redmine.ruby-lang.org/issues/show/4279](http://redmine.ruby-lang.org/issues/show/4279)  
pack.c (pack\_unpack): the resulted string of unpack(‘M’) must have  
ASCII-8BIT encoding (and ENC\_CODERANGE\_VALID). [ruby-core:34482]

I don’t know if there is any reasonable way for Rack to reliably  
return a more correct encoding for the credentials, but that seems to  
be where your incompatible encoding is coming from.

---

<div class="post-metadata">

**Author:** ![oscar-alexander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e36b37/32.png) [@oscar-alexander](https://www.ruby-forum.com/u/oscar-alexander)\
**Post date:** [March 28, 2011, 2:18pm UTC](https://www.ruby-forum.com/t/sqlite3-sinatra-not-returning-results/199313/8 "2011-03-28T14:18:49Z")

</div>

Content preview: On 28.03.2011 02:10, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote: \> The  
credentials  
in Sinatra are unpacked in Rack: \> \> ruby 1.9.2p0: \>\>  
Encoding.default\_external  
\> =\> #Encoding:UTF-8 \>\> Encoding.default\_internal \> =\> nil \>\> s =  
‘hello’  
\> =\> “hello” \>\> s.encoding \> =\> #Encoding:UTF-8 \>\> [s].pack(‘m\*’)

> =\>  
> “aGVsbG8=\n” \>\> [s].pack(‘m\*’).unpack(‘m\*’) \> =\> [“hello”] \>\>  
> [s].pack(‘m\*’).unpack(‘m\*’).first.encoding  
> =\> #Encoding:ASCII-8BIT \> \>  
> rack/blob/master/lib/rack/auth/basic.rb:  
> def credentials \> @credentials ||=  
> params.unpack(“m\*”).first.split(/:/,

1. 

> end \> \> [http://redmine.ruby-lang.org/issues/show/4279](http://redmine.ruby-lang.org/issues/show/4279) \> pack.c  
> (pack\_unpack):  
> the resulted string of unpack(‘M’) must have \> ASCII-8BIT encoding  
> (and ENC\_CODERANGE\_VALID).  
> [ruby-core:34482] \> \> I don’t know if there is any reasonable way  
> for Rack  
> to reliably \> return a more correct encoding for the credentials,  
> but that  
> seems to \> be where your incompatible encoding is coming from. […]

Content analysis details: (-2.9 points, 5.0 required)

pts rule name description

* * *

* * *

-1.0 ALL\_TRUSTED Passed through trusted hosts only via SMTP  
-1.9 BAYES\_00 BODY: Bayes spam probability is 0 to 1%  
[score: 0.0000]  
X-Cloudmark-Analysis: v=1.1  
cv=zlRBWuFCZaNL9+WHNm1pWLowY5Lx061w2zJBJiDkNAU= c=1 sm=0  
a=aofHTkXiRO8A:10 a=NfwdtDP\_n2AA:10 a=8nJEP1OIZ-IA:10 a=xqWC\_Br6kY4A:10  
a=pGLkceISAAAA:8 a=w2PP7KgtAAAA:8 a=VwUrYYIdhK9rIgZAn9gA:9  
a=Dm\_dIbcVq\_-eBn\_k6bYA:7 a=gAU3ZQRgsWUL-DqYwqxl0kMbEBcA:4  
a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117  
Mime-Version: 1.0  
Content-Type: text/plain; charset=ISO-8859-1; format=flowed  
Content-Transfer-Encoding: 8bit  
Precedence: bulk  
Lines: 68  
List-Id: [ruby-talk.ruby-lang.org](http://ruby-talk.ruby-lang.org)  
List-Software: fml [fml 4.0.3 release (20011202/4.0.3)]  
List-Post: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
List-Owner: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
List-Help: [mailto:removed\_email\_address@domain.invalid?body=help](mailto:removed_email_address@domain.invalid?body=help)  
List-Unsubscribe: [mailto:removed\_email\_address@domain.invalid?body=unsubscribe](mailto:removed_email_address@domain.invalid?body=unsubscribe)  
Received-SPF: none (Address does not pass the Sender Policy Framework)  
SPF=FROM;  
[sender=removed\_email\_address@domain.invalid](mailto:sender=removed_email_address@domain.invalid);  
remoteip=::ffff:221.186.184.68;  
[remotehost=carbon.ruby-lang.org](http://remotehost=carbon.ruby-lang.org);  
[helo=carbon.ruby-lang.org](http://helo=carbon.ruby-lang.org);  
[receiver=eq4.andreas-s.net](http://receiver=eq4.andreas-s.net);

On 28.03.2011 02:10, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> =\> #Encoding:UTF-8  
> end
> 
> [http://redmine.ruby-lang.org/issues/show/4279](http://redmine.ruby-lang.org/issues/show/4279)  
> pack.c (pack\_unpack): the resulted string of unpack(‘M’) must have  
> ASCII-8BIT encoding (and ENC\_CODERANGE\_VALID). [ruby-core:34482]
> 
> I don’t know if there is any reasonable way for Rack to reliably  
> return a more correct encoding for the credentials, but that seems to  
> be where your incompatible encoding is coming from.

On 28.03.2011 02:12, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > [http://redmine.ruby-lang.org/issues/show/4279](http://redmine.ruby-lang.org/issues/show/4279)  
> > pack.c (pack\_unpack): the resulted string of unpack(‘M’) must have  
> > ASCII-8BIT encoding (and ENC\_CODERANGE\_VALID). [ruby-core:34482]
> 
> Oops, that’s unpack(‘M’), Rack is using unpack(‘m’).

Thanks, that very informative! Guess proper encoding handling just comes  
with cost and confusion. Although it’s very confusing, it actually looks  
right what ruby is doing. When it decodes base64, how should it know  
it’s encoding? My example, involving PHP:

$ php -r 'echo base64\_encode("this is a t
