From: Gaspard Bucher Date: 2008-05-14T16:27:59+09:00 Subject: Re: disable regexp warning 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. It's the actual run of the regexp in a gsub that prints the error message. Is there a way to detect this error ? Thanks for your help. Gaspard Here is the code in place: http://dev.zenadmin.org/browser/trunk/lib/parser/lib/rules/zena.rb#L231 On Tue, May 13, 2008 at 3:44 PM, Florian Gilcher wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I don't see your problem. > > === > def test > str = "a*(" > > begin > re = /#{str}/ > rescue RegexpError => e > # invalid regexp > "invalid regexp #{str.inspect}: > #{e.message}" > end > end > > puts test.inspect > === > > doesn't print any errors. I double checked that warnings are on and the > warning level was set to highest. > > If it does not work with your ruby version, please post the version string > of you ruby installation (obtained by "ruby -v"). > > Regards, > Florian Gilcher > > > > On May 13, 2008, at 3:08 PM, Gaspard Bucher wrote: > > > > Hi there ! > > > > Is there a way to disable regexp warning ? > > > > I want to do this: > > > > begin > > re = /#{str}/ > > rescue > > # invalid regexp > > return "invalid regexp #{str.inspect}" > > end > > > > without having tons of messages printed on stderr. Any clue ? > > > > Thanks, > > > > Gaspard > > > > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.8 (Darwin) > > iEYEARECAAYFAkgpmyoACgkQJA/zY0IIRZbOSwCeNQelH1ZsQkg7wD6LjFtQwEwy > HYEAoKXytOhB9IkwM4HC7vaGpwkWzLaa > =CkEQ > -----END PGP SIGNATURE----- > >