yob / strip_control_chars

a small ActiveRecord plugin that strips ASCII control chars from string attributes before saving

This URL has Read+Write access

yob (author)
Tue May 05 04:37:43 -0700 2009
README.rdoc

Strip Control Chars

At the lower end of the ASCII range are a few control characters that are generally innocent but useless. Often benign, they sometimes jump out and bite you when you’re trying to do something simple like generate some XML.

If you model doesn’t need them, then remove them before they even make it into your database.

Examples

  class Product < ActiveRecord::Base
    strip_control_chars!
  end

  class Product < ActiveRecord::Base
    strip_control_chars!, :except => :title
  end

  class Product < ActiveRecord::Base
    strip_control_chars!, :only => :description
  end

Installation

Option 1. Load the plugin as a gem

  gem install strip_control_chars
  add "config.gem 'strip_control_chars'" to your environment.rb

Option 2. Use the standard Rails plugin install (assuming Rails >= 2.1).

  ./script/plugin install git://github.com/yob/strip_control_chars.git

Caveats

The translation is done with raw bytes. If you happen to be using anything other than UTF-8 in your models, you’re likely to munge data.

This also means it’s almost certainly not ruby 1.9 compatible. Patches welcome.

Credits

This plugin is essentially a fork of the strip attributes plugin, released under the MIT License by Ryan McGeary.

github.com/rmm5t/strip_attributes

License

Copyright © 2007-2008 Ryan McGeary released under the MIT license Copyright © 2009 James Healy released under the MIT license

en.wikipedia.org/wiki/MIT_License