From: Rick DeNatale Date: 2008-05-14T22:05:38+09:00 Subject: Re: disable regexp warning On Wed, May 14, 2008 at 3:27 AM, Gaspard Bucher wrote: > This is crazy. When I write a simple test case with your example it > works just fine but I still get this message when running all the > tests: > /lib/parser/test/../lib/rules/zena.rb:231: warning: regexp has invalid interval > ./lib/parser/test/../lib/rules/zena.rb:231: warning: regexp has `}' > without escape > compiled-template:1: warning: regexp has invalid interval > compiled-template:1: warning: regexp has `}' without escape > > This message does not come from the simple test I wrote but from this test: > ruby test/helpers/zena_parser_test.rb --name test_basic_show_mean_gsub > > [edit] Ok, I found the problem: > > def test_bad_regexp > assert_equal "invalid regexp \"# {puts > 'I AM MEAN'}\"", validate_regexp("# {puts 'I AM MEAN'}") > end > > private > def validate_regexp(str) > begin > re = /#{str}/ > rescue => e > # invalid regexp > "invalid regexp #{str.inspect}" > end > end > > The regexp is seen as valid even though it is not. I Well the regexp you're testing IS valid, perhaps it's not the regexp you think it is: irb(main):009:0> a = "#{puts 'I am mean'}" I am mean => "" irb(main):010:0> a => "" irb(main):011:0> /#{a}/ => // Remember that puts return nil, and nil.to_s is an empty string. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/