From: "David A. Black" Date: 2004-08-23T00:59:15+09:00 Subject: 1.8.1 gsub/CGI behavior I can't explain Hi -- I have no explanation for this, but here it is. I have a gsub! call in a CGI script (part of RCRchive). It has a block, and the purpose is to filter out unacceptable tags from user input: # GOOD == %w{ a pre code etc} @text.gsub!(/(<((\s*\/?\s*)(\w+)(\s+[^>]+)?)>)/) { if GOOD.include?($4.downcase.strip) # line 85 $1 else "<#{$2}>" end } My error log is full of error messages from calling downcase on nil at line 85. In other words, the match succeeds -- the block is called -- but $4 is nil. ($4 is (/\w+/), which can never be nil if the match succeeds.) $1-$3 are also nil. So is $~. In other words: once inside the block, all evidence of a match disappears. The error messages look like this (minus dates and IP addresses): Premature end of script headers: submitrcr.rb (eval):3:in `__send__': undefined method `downcase' for nil:NilClass (NoMethodError) from (eval):3:in `gsub!' from /usr/local/lib/httpd/htdocs/rcrchive/utils.rb:85:in `initialize', I don't understand the __send__, or the eval, neither of which are in my code. It works fine with 1.9.0, and it works fine from the command line. Nothing I've done makes it work with 1.8.1/CGI, except to re-match the string inside the block. I'm sorry I haven't tracked down what's wrong, but after considerable examination it looks like it's wrong enough that I should mention it. David -- David A. Black dblack@wobblini.net