Ruby 1.9 + MySQL Hack

The default encoding in MySQL is latin1. Ruby 1.9
is a stickler about the encoding of a sequence of bytes.
In this case, a utf8 page name stored in the database comes
back as "ASCII-8BIT" (ie, binary). Coerce that back to utf8.

This doesn't affect SQLite3, and it doesn't affect Ruby 1.8.
It doesn't even affect MySQL databases with "utf8" encoding
(though that has other issues, since MySQL's utf8 support is
broken).
There are probably other, similar problems lurking.
This commit is contained in:
Jacques Distler 2010-01-04 06:41:04 -06:00
parent e3aa626489
commit d786e95a77

View file

@ -82,7 +82,7 @@ class Page < ActiveRecord::Base
# Returns the original wiki-word name as separate words, so "MyPage" becomes "My Page". # Returns the original wiki-word name as separate words, so "MyPage" becomes "My Page".
def plain_name def plain_name
web.brackets_only? ? CGI.escapeHTML(name) : CGI.escapeHTML(WikiWords.separate(name)) web.brackets_only? ? CGI.escapeHTML(name).as_utf8 : CGI.escapeHTML(WikiWords.separate(name)).as_utf8
end end
LOCKING_PERIOD = 30.minutes LOCKING_PERIOD = 30.minutes