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)

And that should do it!

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

  1. 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.

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

  3. 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 Reply

Your email address will not be published. Required fields are marked *