Working with a null character in a text field with Rails and Postgresql

I recently went through a testing round with various inputs to the rails application, and I found a problem with handling null characters of incoming requests. My application is supported by the Postgresql 8.4 database. It turns out Postgresql does not support storing null characters in the standard "text" or "varchar" field. However, when I try to save a string that has a null character in it across the rails, the default behavior seems to truncate the string after the null character. I see this as a problem because the string is checked before truncation occurs. Checks for things like length can be circumvented by inserting null characters, since ruby ​​can handle them perfectly, and truncation only happens when pasting.

I am trying to find a better way to handle these inputs. The ideal behavior for me would be an exception, for example, when dealing with invalid UTF-8 bytes. Right now, the only option I can think of is explicitly checking every line of input for null characters. I would prefer a generalized approach, but I'm not sure where to even start looking. Will there be a postgresql adapter patch to test this option? Or is there some kind of standard approach that I am missing?

+5
source share

All Articles