24

I just updated to try rails 3, using rvm with ruby 1.9.2-p0.

When I run my cucumber specs then I get following strange warnings

/home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string

/home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string

/home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string

My bundle contains following gems...

Using rake (0.8.7) 
Using abstract (1.0.0) 
Using activesupport (3.0.0) 
Using builder (2.1.2) 
Using i18n (0.4.1) 
Using activemodel (3.0.0) 
Using erubis (2.6.6) 
Using rack (1.2.1) 
Using rack-mount (0.6.13) 
Using rack-test (0.5.4) 
Using tzinfo (0.3.23) 
Using actionpack (3.0.0) 
Using mime-types (1.16) 
Using polyglot (0.3.1) 
Using treetop (1.4.8) 
Using mail (2.2.5) 
Using actionmailer (3.0.0) 
Using arel (1.0.1) 
Using activerecord (3.0.0) 
Using activeresource (3.0.0) 
Using bundler (1.0.0) 
Using culerity (0.2.12) 
Using nokogiri (1.4.3.1) 
Using ffi (0.6.3) 
Using json_pure (1.4.6) 
Using rubyzip (0.9.4) 
Using selenium-webdriver (0.0.28) 
Using capybara (0.3.9) 
Using configuration (1.1.0) 
Using diff-lcs (1.1.2) 
Using trollop (1.16.2) 
Using gherkin (2.1.5) 
Using term-ansicolor (1.0.5) 
Using cucumber (0.8.5) 
Using cucumber-rails (0.3.2) 
Using database_cleaner (0.5.2) 
Using launchy (0.3.7) 
Using mysql2 (0.2.3) 
Using rspec-core (2.0.0.beta.20) 
Using rspec-expectations (2.0.0.beta.20) 
Using rspec-mocks (2.0.0.beta.20) 
Using rspec (2.0.0.beta.20) 
Using yard (0.6.0) 
Using pickle (0.4.2) 
Using thor (0.14.0) 
Using railties (3.0.0) 
Using rails (3.0.0) 
Using rspec-rails (2.0.0.beta.20) 
Using spork (0.8.4) 
Using webrat (0.7.1) 

does anyone know how to get rid of these warnings? And where they are coming from?

Ian Vaughan
  • 20,211
  • 13
  • 59
  • 79
server info
  • 1,335
  • 1
  • 14
  • 24
  • I'm having exactly the same thing. I'd love to find out the cause! – Bo Jeanes Sep 11 '10 at 13:25
  • 1
    Hi there - would you mind checkout out the last answer given to this: http://stackoverflow.com/questions/3622394/ruby-1-9-2-strange-warning-when-running-cucumber-specs/7189698#7189698 I believe it fixes your issue and would be grateful if you could mark it as correct. Ty – Peter Nixey Sep 12 '11 at 11:30

5 Answers5

19

There is a good solution available to this that I found on a blog post by Enrico Stahn: http://blog.enricostahn.com/warning-regexp-match-n-against-to-utf-8-strin

The problem is in Rack and has apparently already been fixed in 1.3.0 but you may not be able to upgrade to it yet.

So until you can upgrade to Rack 1.3.0, create the file config/initializers/rack_hotfix.rb with the following content:

# TODO: Can be removed after updating to rack 1.3.0
module Rack
  module Utils
    def escape(s)
      CGI.escape(s.to_s)
    end
    def unescape(s)
      CGI.unescape(s)
    end
  end
end

This worked a charm for me and then I supplemented it with a pending test to on of my RSpec files as a gentle reminder to drop the initializer once Rack's been upgraded.

describe ApplicationController do
  ...
  it "should not include the rack_hotfix.rb initializer after upgrading to rack 1.3.0"

end
Peter Nixey
  • 16,187
  • 14
  • 79
  • 133
  • 2
    When using Rails 3.0.10, you can't upgrade to Rack 1.3+, so this is the trick to use! Personally I do not like having pending tests, if you're like me, you can use these examples: `it "should include the rack_hotfix.rb initializer before rack 1.3.0" do if Rack.release.to_f <= 1.2 Rack::Utils::hotfixed.should be_true end end it "should not include the rack_hotfix.rb initializer after rack 1.3.0" do if Rack.release.to_f >= 1.3 expect { Rack::Utils.hotfixed }.to raise_error end end` Just add this line to the hotfix: `def self.hotfixed true end` – Romain Champourlier Jan 20 '12 at 15:18
7

See:

https://github.com/jnicklas/capybara/issues/87 and https://github.com/jnicklas/capybara/issues/243

for some discussion of the issue. The resolution seems to be that both Capybara and Rack needed to change some things to arrive at a good solution.

If I'm understanding correctly, Rack 1.3 and Capybara 1.0 should solve the issue. At the moment though, Rails 3.0.8 still requires Rack ~> 1.2.1, ignoring Rack 1.3 even if you have it installed. So I think Rails (specifically actionpack) will need to upgrade its dependency to have a clean fix.

Mike Furtak
  • 1,105
  • 1
  • 11
  • 17
6

There is a gem called "escape_utils" that takes care of this problem. Here is the link to an article explaining the problem.

hjuskewycz
  • 1,437
  • 1
  • 14
  • 20
  • 4
    I hate to add a gem and module just to hack around what might be a real warning. Shouldn't we just sit tight until a patch? – Joe Cairns Dec 11 '10 at 20:49
  • Be warned, I tried the solution with escape_utils and it causes the cucumber tests run via spork to break down in their entirety. The error I get in this case is `in \`load': incompatible marshal file format (can't be read) (TypeError) format version 4.8 required; 0.0 given` – Jessie Dedecker Jul 30 '11 at 10:19
  • This is not the best solution as it just causes problems in other areas. – awilkening Aug 15 '11 at 15:19
5

Add this to a file in features/support or put it in the env.rb file:

# Stop endless errors like
# ~/.rvm/gems/ruby-1.9.2-p0@global/gems/rack-1.2.1/lib/rack/utils.rb:16: 
# warning: regexp match /.../n against to UTF-8 string
$VERBOSE = nil

This will suppress those warnings, though I am not sure what is causing them in the first place. I am getting them, also

Bo Jeanes
  • 6,294
  • 4
  • 42
  • 39
0

Maybe your scripts are encoded in ASCII or a different format from UTF-8?

Jorge Israel Peña
  • 36,800
  • 16
  • 93
  • 123
  • What does this mean? Can you provide some details? Is it my editor which needs to treat files as UTF-8? Because the warning comes from Rack as far as I can guess... – server info Sep 02 '10 at 07:24