Phusion Passenger Locale Issues

This blog post might help someone at some point, and it might not. Regardless, it seems rare to run into an obscure problem, find the solution, and actually not have it be something completely kludgy, so in the interest of celebrating a minor victory, here goes.

Ruby 1.8.7 and *&#!ing Curly Quotes.

We have a lot of user input in databases at work, and in several places, big paragraphs of text. Naturally people copy and paste word documents into these things all the time, which is fine in 99.9% of the cases. We’re working with a few new hoops at work, however, and in jumping through a few of them last week, these so-called “smart quotes” started causing me problems.

It turned out that in Ruby 1.8.7–but only in some cases–the interpreter was mangling these non-ascii characters when they were serialized and sent in a JSON response body. I explained the problem to a couple of other devs. One of them couldn’t reproduce it by logging into the development server and running the problematic example on the console, the other could. So there was some disparity in what we were seeing.

Gentoo Locale Settings

Eventually I started thinking about Unicode support on my local box. I use Gentoo Linux as a desktop, which I’m usually extremely happy with, but I’ve never figured out my troubles with unicode in the browser.  The classic Look of Disapproval looks like a couple of empty boxes on that machine. After poking into the locale settings a bit, I discovered my local settings were POSIX. That didn’t seem right.

Same thing when I logged into the dev box. Another developer who uses ubuntu locally saw that all his LC_* settings were en_US.UTF-8, and–surprise, surprise–he was unable to reproduce the issue on the console, whereas it presented to me. Finally onto something.

After some digging, I found that where several other Gentoo users have a 02locale file in /etc/env.d, and I didn’t. After adding that file and logging out and back in, my locale settings matched up with the other developer, and boom: the problem no longer presented on the console for me.

Apache and Phusion Passenger

It turns out there’s an annoying bug in Passenger where it doesn’t pick up environment variables from Apache in the way that it should.  For now, we’ve been able to work around the issue by adding a wrapper script to the ruby executable that Passenger uses, and set the necessary LANG variable in there. It’s not the greatest solution in the world but it’s clean, doesn’t require messing with the system-wide ruby binary, and should cause no speed issue.

If anyone else has run into this and found a cleaner solution, please drop me a comment or shoot me an email.

Comments

blog comments powered by Disqus