Fixed Bug: Certain text crashes yaml revision loading

Sebastien Clediere reports that:

“after importing from instiki, soks was crashing due to a  problem with a textile file (it only had a single character and it was ok the first time, but each time there was the associated yaml revision file, it crashed.). In order to track it down, I changed the following code of soks-storage.rb:”


def load_revisions( page )
  return [] unless File.exists?( filename_for_revisions( page.name ) )
  revisions = []
  begin
    File.open( f=filename_for_revisions( page.name ) ) do |file| 
      YAML.each_document( file ) { |array| revisions[ array[0] ] = Revision.new( page, *array ) }
    end
  rescue
    puts $!.to_s + " in file #{f}" 
  end
  revisions.each_with_index { |r,i| $stderr.puts "#{page.name} missing revision #{i}" unless r }
  revisions
end

Sebastien reports that importing an Instiki page where the content had been deleted, leaving only an 0×0A (newline?) character. I will do some testing to see if I can find out what is going on, but I would be grateful of other reports relating to this bug.

Thanks

tamc2


Ok. Tracked down and fixed:

The loading always assumes their is at least one revision in the revisions file. If the page is blank, then no revision is created and an empty array is written to the revision file. This causes an exception on the file load.

The fix is to put some error checking in the loading code in lib/soks-storage.rb#load_revisions:


File.open( filename_for_revisions( page.name ) ) { |file| 
    YAML.each_document( file ) { |array| 
    next unless array.size == 4
    next unless array[0].is_a? Integer 
    revisions[ array[0] ] = Revision.new( page, *array ) } 
}

So, thank you to Sebastien for spotting the bug! I will include the fix in the next version.

tamc2

Fixed in v-0-0-6

Edit this page or watch for changes using RSS.