I recently went through a round of testing with various inputs on my rails application, and I've discovered a problem with how null characters in incoming requests are handled. My application is backed by a Postgresql 8.4 database. It turns out that Postgresql doesn't support storing null characters in the standard 'text' or 'varchar' field. However, when I try to store a string that does have a null character in it through rails, the default behavior appears to be truncating the string after the null character. I view this as a problem because the string is validated before the truncation occurs. Validations for things like length can be bypassed by inserting the null characters since ruby can deal with them perfectly fine and the truncation only happens on insert.
I'm trying to figure out the best way of dealing with these inputs. Ideal behavior for me would be throwing an exception somewhere like when dealing with invalid UTF-8 bytes. Right now, the only option that I can think of is explicitly checking every input string for null characters. I would much rather have a generalized approach, but I'm not sure where to even start looking. Would patching the postgresql adapter to check for this be an option? Or is there some standard approach that I've been missing?