藤岡です。 > Railsでvalidateにひっかかったときに赤い枠がついたりするような感じで > 以下のように引っかかったフィールドに何か印をつけるのに使えるかも、 > というイメージです。 > > invalid_fields = {} > cgi = CGI.new(..., :... =>proc {|field_name, field_value| > invalid_fields[field_name] = field_value > }) > ... > cgi.out(...) { > ... > cgi.text_field({...,"name"=>"some_text", "class"=> > invalid_fields.include?("some_text") ? "invalid" : "" > }) > ... > } > > こんな感じでしょうか。 invalid_fields={} cgi=CGI.new(:accept_charset=>"EUC-JP"){|field_name,field_value| invalid_fields[field_name] = field_value } こんな感じで使えます。newのブロックに渡すのはいいのかどうか微妙ですが。 メソッドのブロックが空いているので詰め込んでみました。 Index: lib/cgi/core.rb =================================================================== --- lib/cgi/core.rb (リビジョン 19454) +++ lib/cgi/core.rb (作業コピー) @@ -598,8 +598,21 @@ stdinput.read(Integer(env_table['CONTENT_LENGTH'])) or '' else read_from_cmdline - end + end.dup.force_encoding(@accept_charset) ) + if @accept_charset!="ASCII-8BIT" || @accept_charset!=Encoding::ASCII_8BIT + @params.each do |key,values| + values.each do |value| + unless value.valid_encoding? + if @accept_charset_error_block + @accept_charset_error_block.call(key,value) + else + raise "Accept-Charset encoding error" + end + end + end + end + end end @cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] or env_table['COOKIE'])) @@ -665,7 +678,24 @@ # from the command line or (failing that) from standard input. Otherwise, # cookies and other parameters are parsed automatically from the standard # CGI locations, which varies according to the REQUEST_METHOD. - def initialize(type = "query") + attr_reader :accept_charset + @@accept_charset="UTF-8" + def self.accept_charset + @@accept_charset + end + def self.accept_charset=(accept_charset) + @@accept_charset=accept_charset + end + def initialize(options = {},&block) + @accept_charset_error_block=block if block_given? + @options={:accept_charset=>@@accept_charset} + case options + when Hash + @options.merge!(options) + when String + @options[:tag_maker]=options + end + @accept_charset=@options[:accept_charset] if defined?(MOD_RUBY) && !ENV.key?("GATEWAY_INTERFACE") Apache.request.setup_cgi_env end @@ -677,7 +707,7 @@ @output_cookies = nil @output_hidden = nil - case type + case @options[:tag_maker] when "html3" require 'cgi/html' extend Html3