[Feature #542] cgi.rb : CGI::unescape return encoding

In article [email protected],
Tietew [email protected] writes:

e$B8D?ME*$K$O!"$I$N%U%#!<%k%I$,IT@5$J$N$+$H$$$&$3$H$K6=L#$O$J$$$N$G!"e(B
true/false e$B$,JV$kDxEY$G9=$$$^$;$s!#B>$N?M$N0U8+$bJ9$-$?$$$G$9!#e(B

e$BH4$17j$rKI$0$H$$$&0UL#$G$ONc30$NJ}$,$$$$$N$+$J$"!#e(B

e$BIaDL$ONc30$G!“<+J,$G3N$+$a$k$H$$$&$R$H$N$?$a$K8!::$7$J$$A*Bre(B
e$B;h$r$D$1$k!”$H$$$&$"$?$j$8$c$J$$$G$9$+!#e(B

CGI.new(:accept_encoding=>“…”,
“name1”=>:file,
“name2”=>…)

e$B$G!"8!::$7$J$$$J$ie(B

CGI.new(:accept_encoding=>:no_validation,
“name1”=>:file,
“name2”=>…)

e$B$H$+!#e(B

In article [email protected],
Tanaka A. [email protected] writes:

e$B$G!"8!::$7$J$$$J$ie(B

CGI.new(:accept_encoding=>:no_validation,

e$B8!::$7$J$$$J$ie(B “ASCII-8BIT” e$B$r;XDj$9$k$@$1$G$$$$$+$b!#e(B

e$B@>;3OB9-$G$9!#e(B

At Mon, 22 Sep 2008 18:55:07 +0900,
Tietew wrote:

e$B2?$i$+$N7A$NItJ,$N4uK>$O$"$j$^$9$+!)e(B
e$BNc$($Pe(B@encoding_errorse$B$Ne(Barraye$B$r:n$C$F9`L\L>$r%W%C%7%e$9$k$H$+e(B

e$B8D?ME*$K$O!"$I$N%U%#!<%k%I$,IT@5$J$N$+$H$$$&$3$H$K6=L#$O$J$$$N$G!"e(B
true/false e$B$,JV$kDxEY$G9=$$$^$;$s!#B>$N?M$N0U8+$bJ9$-$?$$$G$9!#e(B

e$BH4$17j$rKI$0$H$$$&0UL#$G$ONc30$NJ}$,$$$$$N$+$J$"!#e(B

e$BIT@5%(%s%3!<%G%#%s%0$r8!=P$7$?$H$-$K<B9T$9$k%V%m%C%/$r;XDj$G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K6=L#$O$J$$$N$G!"e(B
true/false e$B$,JV$kDxEY$G9=$$$^$;$s!#B>$N?M$N0U8+$bJ9$-$?$$$G$9!#e(B

e$BH4$17j$rKI$0$H$$$&0UL#$G$ONc30$NJ}$,$$$$$N$+$J$"!#e(B

e$BIT@5%(%s%3!<%G%#%s%0$r8!=P$7$?$H$-$K<B9T$9$k%V%m%C%/$r;XDj$G$-$ke(B
e$B$h$&$K$7$F!";XDj$,$J$+$C$?>l9g$N%G%U%)%k%H$ONc30$G!"$I$N%U%#!<%k%I$+e(B
e$BCN$j$?$1$l$P$=$3$G;D$9$h$&$K$9$k$H$+e(B?

e$B$3$l!"%3!<%I$N%5%s%W%k$r:n$l$^$;$s$G$7$g$&$+!)e(B
e$B$3$s$JIw$K;H$$$?$$$_$?$$$J$d$D!#e(B

e$B@>;3OB9-$G$9!#e(B

At Mon, 22 Sep 2008 20:17:26 +0900,
Fujioka wrote:

e$BIT@5%(%s%3!<%G%#%s%0$r8!=P$7$?$H$-$K<B9T$9$k%V%m%C%/$r;XDj$G$-$ke(B
e$B$h$&$K$7$F!";XDj$,$J$+$C$?>l9g$N%G%U%)%k%H$ONc30$G!"$I$N%U%#!<%k%I$+e(B
e$BCN$j$?$1$l$P$=$3$G;D$9$h$&$K$9$k$H$+e(B?

e$B$3$l!"%3!<%I$N%5%s%W%k$r:n$l$^$;$s$G$7$g$&$+!)e(B
e$B$3$s$JIw$K;H$$$?$$$_$?$$$J$d$D!#e(B

Railse$B$Ge(Bvalidatee$B$K$R$C$+$+$C$?$H$-$K@V$$OH$,$D$$$?$j$9$k$h$&$J46$8$Ge(B
e$B0J2<$N$h$&$K0z$C$+$+$C$?%U%#!<%k%I$K2?$+0u$r$D$1$k$N$K;H$($k$+$b!"e(B
e$B$H$$$&%$%a!<%8$G$9!#e(B

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” : “”
})

}

e$BF#2,$G$9!#e(B


cgi.text_field({…,“name”=>“some_text”, “class”=>
invalid_fields.include?(“some_text”) ? “invalid” : “”
})

}

e$B$3$s$J46$8$G$7$g$&$+!#e(B
invalid_fields={}
cgi=CGI.new(:accept_charset=>“EUC-JP”){|field_name,field_value|
invalid_fields[field_name] = field_value
}
e$B$3$s$J46$8$G;H$($^$9!#e(Bnewe$B$N%V%m%C%/$KEO$9$N$O$$$$$N$+$I$&$+HyL/$G$9$,!#e(B
e$B%a%=%C%I$N%V%m%C%/$,6u$$$F$$$k$N$G5M$a9~$s$G$_$^$7$?!#e(B

Index: lib/cgi/core.rb

— lib/cgi/core.rb (e$B%j%S%8%g%se(B 19454)
+++ lib/cgi/core.rb (e$B:n6H%3%T!<e(B)
@@ -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

e$BF#2,$G$9!#e(B

e$B$3$s$J46$8$G$7$g$&$+!#e(B
invalid_fields={}
cgi=CGI.new(:accept_charset=>“EUC-JP”){|field_name,field_value|
invalid_fields[field_name] = field_value
}
e$B$3$s$J46$8$G;H$($^$9!#e(Bnewe$B$N%V%m%C%/$KEO$9$N$O$$$$$N$+$I$&$+HyL/$G$9$,!#e(B
e$B%a%=%C%I$N%V%m%C%/$,6u$$$F$$$k$N$G5M$a9~$s$G$_$^$7$?!#e(B

e$BBg$-$JH?BP$,$J$1$l$PL@F|$"$?$j$K$H$j$"$($:%3%_%C%H$7$F$7$^$&M=Dj$G$9!#e(B
e$B%^%k%A%Q!<%H$N$[$&$O$^$@2?$b$d$C$F$$$^$;$s$,!"e(B
e$B%(%s%3!<%G%#%s%00JA0$KF0$-$=$&$K$J$$$N$G!"e(B
e$B:#8eBP1~$7$F$$$-$^$9!#e(B