It has been a tough week at Panmind’s HQ because, after many innovations
and new features released for you, we had to employ some counter measures
for the many, randomic, errors that you were experiencing while using the
platform.
We fixed:
* an error that caused the interface to hang when creating a ReS
contextually to the publishing of a new content
* a validation error that caused inability to publish when copy-pasting
text into the Project writeboards and messages editor
* an error that could happen when an user left the “sign up” page open
for too much time before actually signing up
* a Facebook login bug that prevented you to use it, unless you clicked
very quickly on the Facebook login button .
Moreover, we were challenged by a multi-faceted bug that currently affects
applications using the very same technology stack that we use, Ruby 1.9
and Rails 2.3: the infamous “Encoding bug” that appears to the developer
as “Invalid byte sequence in US-ASCII” or “incompatible character encodings”.
For you user, it meant that, randomly, the application could tell you that
“something went wrong”, either in the whole page or via the lousy red box
that we use on Project to report errors. If you experienced this error in
the last month, you are now safe and everything will work as expected.
For the technically inclined, or for other developers facing the same
challenge, we cooked up a monkey patch to ActionView and ERb and a Rack
middleware to brutally close these issues, and while our solution is
not the most elegant or correct, it actually fixes these issues for our
users.
Broadly, the error is caused by the source encoding of Rails 2.3 files,
that miss the “magic comment” that set the encoding thus they default to
the ASCII-8BIT one. Because these sources contain the Strings used by
all _tag helpers in Rails, whenever you try to make them generate an
HTML tag containing UTF-8 characters, you’ll get an Exception because
Strings coded in ASCII-8BIT and UTF-8 cannot be concatenated safely.
Our patch overwrites the 4 core methods in the AV::Helpers::TagHelper
and the two methods in InstanceTag (used by form_for() and friends)
to force the encoding of their returned values to UTF-8.
Moreover, ERB::Util.html_escape (the h()) was overriden as well, by
forcing the encoding to UTF-8 on the string to be escaped, and we also
added a Rack Middleware to recode all the request parameters coming in
from HTTP clients i UTF-8.
As we said, these are brutal solutions for a problem that is properly
fixed by upgrading to the latest versions of the framework (Rails 3) and
the interpreter (Ruby 1.9.2p0), but on a big application like Panmind
this task needs time, and we wanted to fix errors for our users *now*.
The code of our combined patch to Rails 2.3 is available as a GitHub
gist, download it here: https://gist.github.com/669537 – and let us hear
from you in the comments!
Comments (0)