diff -Ncr html-fillinform-0.24.orig/lib/html/fillinform.rb html-fillinform-0.24-cur/lib/html/fillinform.rb
*** html-fillinform-0.24.orig/lib/html/fillinform.rb	2003-01-14 22:13:15.000000000 +0900
--- html-fillinform-0.24-cur/lib/html/fillinform.rb	2004-03-16 22:29:02.868506160 +0900
***************
*** 32,38 ****
        text_area = nil
        select_box = nil
        option_tag = nil
!       HTMLSplit.new(@html).document.each do |tag|
  	##
  	# check <form> name
  	if tag.is_a?(EndTag) and tag.name == 'form'
--- 32,45 ----
        text_area = nil
        select_box = nil
        option_tag = nil
! 
!       if @output != ""
!         output_tmp = @output
!       else
!         output_tmp = @html
!       end
!       @output = ''
!       HTMLSplit.new(output_tmp).document.each do |tag|
  	##
  	# check <form> name
  	if tag.is_a?(EndTag) and tag.name == 'form'
***************
*** 41,46 ****
--- 48,55 ----
  	  next
  	end
  	if tag.is_a?(StartTag) and tag.name == 'form'
+           raise RuntimeError, "No attribute in the form tag" if !tag.attr
+           raise RuntimeError, "No 'action' attribute in the form tag" if !tag.attr['action']
  	  current_form = tag.attr['name']
  	  @output << tag.to_s
  	  next
***************
*** 55,61 ****
  	if tag.is_a?(EndTag) and tag.name == 'textarea'
  	  require 'cgi'
  	  if hash[text_area] and hash[text_area].is_a?(Array)
! 	    @output << CGI.escapeHTML(hash[text_area][0])
  	  elsif hash[text_area]
  	    @output << CGI.escapeHTML(hash[text_area])
  	  end
--- 64,72 ----
  	if tag.is_a?(EndTag) and tag.name == 'textarea'
  	  require 'cgi'
  	  if hash[text_area] and hash[text_area].is_a?(Array)
!             if hash[text_area].first
!               @output << CGI.escapeHTML(hash[text_area][0])
!             end
  	  elsif hash[text_area]
  	    @output << CGI.escapeHTML(hash[text_area])
  	  end
***************
*** 66,72 ****
  	if text_area and hash[text_area]
  	  require 'cgi'
  	  if hash[text_area].is_a?(Array)
! 	    @output << CGI.escapeHTML(hash[text_area][0])
  	  else
  	    @output << CGI.escapeHTML(hash[text_area])
  	  end
--- 77,85 ----
  	if text_area and hash[text_area]
  	  require 'cgi'
  	  if hash[text_area].is_a?(Array)
!             if hash[text_area].first
!               @output << CGI.escapeHTML(hash[text_area][0])
!             end
  	  else
  	    @output << CGI.escapeHTML(hash[text_area])
  	  end
***************
*** 97,104 ****
  		break
  	      end
  	    end
! 	  elsif hash[select_box] == tag.to_s.chomp.strip
! 	    option_tag.attr['selected'] = true
  	  end
  	  @output << option_tag.to_s << tag.to_s
  	  option_tag = nil
--- 110,121 ----
  		break
  	      end
  	    end
!           elsif hash[select_box]
!             if hash[select_box] == tag.to_s.chomp.strip
!               option_tag.attr['selected'] = true
!             else
!               option_tag.attr.delete('selected')
!             end
  	  end
  	  @output << option_tag.to_s << tag.to_s
  	  option_tag = nil
***************
*** 112,121 ****
  	  unless tag.attr and tag.attr['value']
  	    option_tag = StartTag.new('option')
  	    option_tag.attr = tag.attr || {}	    
- 	    if option_tag.attr['selected']
- 	      # delete original 
- 	      option_tag.attr.delete('selected')
- 	    end
  	    next
  	  end
  
--- 129,134 ----
***************
*** 126,142 ****
  		chk = true
  	      end
  	    end
! 	  elsif hash[select_box] == tag.attr['value']
! 	    tag.attr['selected'] = true
! 	    chk = true
  	  elsif hash[select_box]
! 	    tag.attr.delete('selected')
! 	    chk = false
! 	  end
! 	  if chk
! 	    tag.attr['selected'] = true
! 	  else
! 	    tag.attr.delete('selected')
  	  end
  	  @output << tag.to_s
  	  next
--- 139,155 ----
  		chk = true
  	      end
  	    end
!             if chk
!               tag.attr['selected'] = true
!             else
!               tag.attr.delete('selected')
!             end
  	  elsif hash[select_box]
!             if hash[select_box] == tag.attr['value']
!               tag.attr['selected'] = true
!             else
!               tag.attr.delete('selected')
!             end
  	  end
  	  @output << tag.to_s
  	  next
***************
*** 183,228 ****
  	    ##
  	    # <input type="checkbox">
  	  elsif type == 'checkbox'
! 
! 	    chk = false
! 	    if hash[tag.attr['name']].is_a?(Array)
! 	      hash[tag.attr['name']].each do |v|
! 		if v == tag.attr['value']
! 		  chk = true
! 		end
! 	      end
! 	    elsif hash[tag.attr['name']] == tag.attr['value']
! 	      tag.attr['checked'] = true
! 	    elsif hash[tag.attr['name']]
! 	      tag.attr.delete('checked')
! 	    end
! 	    # for multiple select
! 	    if chk
! 	      tag.attr['checked'] = true
! 	    else
! 	      tag.attr.delete('checked')
! 	    end
  	    @output << tag.to_s
  	    next
!    	  elsif type == 'submit' or type == 'reset' or type == 'button'
!    	    @output << tag.to_s
!    	    next
  	  else
  	    ##
  	    # text,hidden,password ..
! 	    require 'cgi'
! 	    if hash[tag.attr['name']].is_a?(Array) 
! 	      tag.attr['value'] = hash[tag.attr['name']][0]
!  	      if tag.attr['value'] == nil
!  		tag.attr['value'] = ''
!  	      end
  	      @output << tag.to_s
  	      next
  	    elsif hash[tag.attr['name']] 
! 	      tag.attr['value'] = hash[tag.attr['name']]
! 	      if tag.attr['value'] == nil
! #		tag.attr['value'] = ''
! 	      end
  	      @output << tag.to_s
  	      next
  	    else
--- 196,244 ----
  	    ##
  	    # <input type="checkbox">
  	  elsif type == 'checkbox'
!             case hash[tag.attr['name']]
!             when Array
!               chk = false
!               hash[tag.attr['name']].each do |v|
!                 if (tag.attr['value'] && v == tag.attr['value']) ||
!                    (!tag.attr['value'] && v == "on")
!                   chk = true
!                 end
!               end
!               # for multiple select
!               if chk
!                 tag.attr['checked'] = true
!               else
!                 tag.attr.delete('checked')
!               end
!             when String
!               if (tag.attr['value'] && hash[tag.attr['name']] == tag.attr['value']) ||
!                  (!tag.attr['value'] && hash[tag.attr['name']] == "on")
!                 tag.attr['checked'] = true
!               else
!                 tag.attr.delete('checked')
!               end
!             when NilClass, FalseClass
!             else
!               raise TypeError, "The value was #{hash[tag.attr['name']].class}. must be an Array, String or nil."
!             end
  	    @output << tag.to_s
  	    next
! #   	  elsif type == 'submit' or type == 'reset' or type == 'button'
! #   	    @output << tag.to_s
! #   	    next
  	  else
  	    ##
  	    # text,hidden,password ..
!             #require 'cgi'
! 	    if hash[tag.attr['name']].is_a?(Array)
!               if hash[tag.attr['name']].first
!                 tag.attr['value'] = hash[tag.attr['name']][0]
!               end
  	      @output << tag.to_s
  	      next
  	    elsif hash[tag.attr['name']] 
!               tag.attr['value'] = hash[tag.attr['name']].to_s
  	      @output << tag.to_s
  	      next
  	    else
diff -Ncr html-fillinform-0.24.orig/test/test-fil.rb html-fillinform-0.24-cur/test/test-fil.rb
*** html-fillinform-0.24.orig/test/test-fil.rb	1970-01-01 09:00:00.000000000 +0900
--- html-fillinform-0.24-cur/test/test-fil.rb	2003-11-03 16:25:56.000000000 +0900
***************
*** 0 ****
--- 1,223 ----
+ 
+ # FillInForm¤Î¥Æ¥¹¥È
+ 
+ require "html/fillinform"
+ require "runit/testcase"
+ require "runit/cui/testrunner"
+ 
+ class Test2 < RUNIT::TestCase
+   # actionÂ°À­¤Î¤Ê¤¤form¥¿¥°¤Ï¥¨¥é¡¼
+   def test1
+     fif = nil
+     assert_no_exception() {
+       fif = HTML::FillInForm.new("<form></form>")
+     }
+     assert_exception(RuntimeError) {
+       fif.fill({})
+     }
+   end
+ 
+   # ¥¿¥°¤¬¸«¤Ä¤«¤é¤Ê¤¤¤È¤­¤Ï¡¤Ìµ»ë
+   def test2
+     s = <<EOF
+ <form action="./t.rb">
+ <input name="t" type="text">
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     assert_no_exception() {
+       fif.fill({"foo" => "bar"})
+     }
+   end
+ 
+   # input[type = "text"]
+   def test4
+     s = <<EOF
+ <form action="./t.rb">
+ <input name="t" type="text">
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     fif.fill({})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb">
+ <input name="t" type="text">
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     fif.fill({"t" => "foo"})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb">
+ <input name="t" type="text" value="foo">
+ </form>
+ EOF
+ 
+     s = <<EOF
+ <form action="./t.rb">
+ <input name="t" type="text" value="bar">
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     fif.fill({})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb">
+ <input name="t" type="text" value="bar">
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     fif.fill({"t" => 100})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb">
+ <input name="t" type="text" value="100">
+ </form>
+ EOF
+   end
+ 
+   # select
+   def test5
+     s = <<EOF
+ <form action="./t.rb">
+ <select name="t">
+   <option>v1
+   <option selected>v2
+ </select>
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     fif.fill({})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb">
+ <select name="t">
+   <option>v1
+   <option selected>v2
+ </select>
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     fif.fill({"t" => "v1"})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb">
+ <select name="t">
+   <option selected>v1
+   <option>v2
+ </select>
+ </form>
+ EOF
+ 
+     s = <<EOF
+ <form action="./t.rb">
+ <select name="t">
+   <option value="1">v1
+   <option value="2">v2
+ </select>
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     fif.fill({})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb">
+ <select name="t">
+   <option value="1">v1
+   <option value="2">v2
+ </select>
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     fif.fill({"t" => "2"})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb">
+ <select name="t">
+   <option value="1">v1
+   <option selected value="2">v2
+ </select>
+ </form>
+ EOF
+   end
+ 
+   # '<'¤ä'>'¤Ï¥¨¥¹¥±¡¼¥×¤µ¤ì¤ë
+   def test6
+     s = <<EOF
+ <form action="./t.rb">
+ <input name="t">
+ <textarea name="u"></textarea>
+ </form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     fif.fill({"t" => "<\">", "u" => "<\">"})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb">
+ <input name="t" value="&lt;&quot;&gt;">
+ <textarea name="u">&lt;&quot;&gt;</textarea>
+ </form>
+ EOF
+   end
+ 
+   def test7
+     s = <<EOF
+ <form action="./t.rb"><input type="checkbox" name="t"></form>
+ EOF
+     fif = HTML::FillInForm.new(s)
+     assert_exception(TypeError) {fif.fill({"t" => true})}
+ 
+     fif = HTML::FillInForm.new(s)
+     fif.fill({"t" => "on"})
+     assert_equal(<<EOF, fif.output)
+ <form action="./t.rb"><input checked name="t" type="checkbox"></form>
+ EOF
+   end
+ end
+ 
+ RUNIT::CUI::TestRunner.run(Test2.suite)
+ 
+ def test1
+   fif = HTML::FillInForm.new(<<EOF)
+ <html>
+ <form action="./fil.rb">
+ <input type="password" name="c2a" value="v"> <input type="password" name="c2b">
+ 
+ <input type="checkbox" name="c3a" checked> <input type="checkbox" name="c3aa">
+ <input type="checkbox" name="c3b">
+ <input type="checkbox" name="c3c" checked>
+ 
+ <input type="radio" name="c4a" value="s1"> <input type="radio" name="c4a" checked value="s2">
+ <input type="radio" name="c4b" checked value="s1"> <input type="radio" name="c4b" value="s2">
+ 
+ <input type="hidden" name="c5a" value="hoge"> <input type="hidden" name="c5b">
+ 
+ <input type="file" name="c6a"> <input type="file" name="c6b">
+ 
+ <textarea name="c8a">
+ ¤Õ¤Ë¤Õ¤Ë
+ </textarea>
+ <textarea name="c8b">
+ </textarea>
+ <textarea name="c8bb">
+ foo
+ </textarea>
+ 
+ <button name="c9a" value="foo">¥Ü¥¿¥ó</button>
+ <button name="c9b" value="foo">¥Ü¥¿¥ó</button>
+ 
+ </form>
+ </html>
+ EOF
+   fif.fill({
+     "c1b" => "bar",         # ok
+     "c1bb" => "",
+     "c2b" => "hoge",        # ok
+     "c3b" => "on",
+     "c3c" => "off",
+     "c4b" => "s2",
+     "c5b" => "baz",
+     "c6b" => "config.sys",
+     "c7b" => "v2",
+     "c7bb" => "1",
+     "c8b" => "bar",
+     "c8bb" => "baz",
+     "c9b" => "bar"
+   })
+   print "Content-Type:text/html\n\n"
+   print fif.output
+ end
+ 
+ #test1
