Ticket #359 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

Formatter::PDF draw_table is destructive to table_format

Reported by: sandal Assigned to:
Milestone: ruport 1.2 defects Keywords:
Cc:

Description

because table_format consists of nested hashes, a deep copy of the data is necessary if any of our methods are to use Hash#delete, which the column options code uses copiously

The problematic code is here:

    def draw_table(table_data, format_opts={})
      m = "PDF Formatter requires column_names to be defined"
      raise FormatterError, m if table_data.column_names.empty?
      
      table_data.rename_columns { |c| c.to_s } 
      
      # if table_format[:something] is a hash, it's not duplicated, so doing
      # format_opts[:something].delete(:something_else) effects the original 
      # table_format object
      format_opts = table_format.merge(format_opts) if table_format   

Tentative fix, without tests:

  if table_format
    format_opts = Marshal.load(Marshal.dump(table_format.merge(format_opts))) 
  end   

We should look for this issue in other areas of Ruport, but this fixes the specific problem I ran into.

To reproduce the issue, try setting up a template which sets column headers to bold, then run draw_table twice.

Change History

10/18/07 11:05:25 changed by sandal

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in r1187, see test below

  # draw_table has destructive behavior on nested rendering options (#359)
  def test_draw_table_should_not_destroy_nested_rendering_options
     f = Ruport::Formatter::PDF.new   
     f.options = Ruport::Renderer::Options.new 
     f.options[:table_format] =  
       { :column_options => { :heading => {:justification => :center }}}
     f.draw_table [[1,2,3],[4,5,6]].to_table(%w[a b c])  
     assert_equal({ :justification => :center }, 
                  f.options[:table_format][:column_options][:heading])      
  end