lib/mechanize/form.rb in mechanize-2.0.pre.1 vs lib/mechanize/form.rb in mechanize-2.0.pre.2

- old
+ new

@@ -27,12 +27,21 @@ extend Mechanize::ElementMatcher attr_accessor :method, :action, :name attr_reader :fields, :buttons, :file_uploads, :radiobuttons, :checkboxes + + # Content-Type for form data (i.e. application/x-www-form-urlencoded) attr_accessor :enctype + # Character encoding of form data (i.e. UTF-8) + attr_accessor :encoding + + # When true, character encoding errors will never be never raised on form + # submission. Default is false + attr_accessor :ignore_encoding_error + alias :elements :fields attr_reader :form_node attr_reader :page @@ -44,10 +53,12 @@ @name = node['name'] @clicked_buttons = [] @page = page @mech = mech + @encoding = node['accept-charset'] || (page && page.encoding) || nil + @ignore_encoding_error = false parse end # Returns whether or not the form contains a field with +field_name+ def has_field?(field_name) @@ -171,19 +182,20 @@ } end private :proc_query def from_native_charset str - Util.from_native_charset(str,page && page.encoding) + Util.from_native_charset(str, encoding, @ignore_encoding_error, @mech && @mech.log) end private :from_native_charset # This method builds an array of arrays that represent the query # parameters to be used with this form. The return value can then # be used to create a query string for this form. def build_query(buttons = []) query = [] + @mech.log.info("form encoding: #{encoding}") if @mech && @mech.log (fields + checkboxes).sort.each do |f| case f when Form::CheckBox if f.checked @@ -393,10 +405,10 @@ end # Find all textarea tags form_node.search('textarea').each do |node| next unless node['name'] - @fields << Field.new(node, node.inner_text) + @fields << Textarea.new(node, node.inner_text) end # Find all select tags form_node.search('select').each do |node| next unless node['name']