Crimpy Code Making my way as a geeky musician

31Aug/1012

warning: regexp match /…/n against to UTF-8 string error when using Cucumber

Ever since updating my environment to Rails 3.0.0 / RSpec 2.0.0.beta.20 / Cucumber 0.8.5 / Capybara 0.3.9 / Autotest 4.3.2, I've been getting the following error when Cucumber runs my features:

GEM_PATH/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string

It seems that Rack is having a problem whenever UTF-8 strings are sent in the params. Thankfully, these guys found a solution.

For a more verbose description, check out that page. Here's the quick and dirty:

Install the escape_utils gem by including this in your Gemfile:

gem "escape_utils"

Run bundle install to install the gem. Now, create a new file: RAILS_ROOT/config/initializers/escape_utils.rb with the following content:

module Rack
  module Utils
    def escape(s)
      EscapeUtils.escape_url(s)
    end
  end
end

And that should do it!

Comments (12) Trackbacks (2)
  1. Thanks! This works.

  2. If you are using Rails 3 and escape_utils be warned that version 0.2.0 has a buffer over-read issue that will cause two characters to be truncated from your post parameters randomly under load. Once we upgraded to 0.2.3 the problem went away.

  3. Perfect! What an annoying little bug.

  4. Thanks! Worked great for me!

  5. Works for me too with Rails 3.0.9. Thanks.

  6. Thank you! Worked greate!

  7. Thank you. : )

  8. Great fix, thank you. Point of interest, the ‘these guys’ link resulted in an nginx 500 error for me today. OH THE IRONY.

  9. Just watch what you put in 3.2 and on production…. basically i have a unicorn error log full of “cache error: uninitialized constant Rack::Utils::EscapeUtils” and a line going to : home/blah/config/initializers/escape_utils.rb:7:in `escape’ in case google should cache this.


Leave a comment