2

I want to store mysql regular epxression to mysql database field. Specifically I want to store word boundaries expression into the database. For example:

[[:<:]]my expression here[[:>:]]

If I put this value directly into the database (for example using Sequel Pro) the value is stored correctly.

Problem occur when I want to store this value through Ruby on Rails:

my_instance.sql_expression = "[[:<:]]my expression here[[:>:]]"
my_instance.save 
=> true

But value that is actually stored to database looks like this:

my_instance.sql_expression
=> "[[::]]"

It seems that in string Rails ignore everything what is between "<" and ">" including signs itselfs.

The project is in Ruby 1.8.7 and Rails 2.3.5.

  • 6
    Are you certain that what is saved is mangled? I'd guess that what is mangled is the _output_. For more detailed information, see http://stackoverflow.com/questions/4251284/raw-vs-html-safe-vs-h-to-unescape-html and see if that looks like what is going on here. – sarnold Dec 07 '11 at 08:49
  • Are those examples being run from the REPL and pasted directly? (The 2nd has a typo?) –  Dec 07 '11 at 09:01
  • What do you get when you store `Lorem Ipsum`? – Álvaro González Dec 07 '11 at 09:07
  • I am sure that what is mangled is the value that is going from rails to database. I checked the log in terminal and of course value in database. When I store `Lorem Ipsum` after a save method is called in the attribute is only `Lorem Ipsum`. I don't know how to tell that the string in the attribute is html_safe??? – Tomáš Porazil Dec 07 '11 at 09:25
  • I just tested with 1.9.2 and rails 2.3.5. I saved values to DB string and text fields. Both values were saved correctly. Can you please go to console and save an record, reload it and see if data is OK? – Iuri G. Dec 15 '11 at 16:06

1 Answers1

1

This sounds like you're using something like xss_terminate to filter your models before saving them. I'd look in your model definition for something which has a before_save or other hook that might be intrusively doing this.

This is not standard Rails behavior.

Cyberfox
  • 1,125
  • 7
  • 13