Ticket #11: tarantula_hpricot.patch

File tarantula_hpricot.patch, 3.5 kB (added by someone23, 4 months ago)
  • tarantula.orig/lib/relevance/tarantula/form.rb

    old new  
    11class Relevance::Tarantula::Form 
    22  extend Forwardable 
    3   def_delegators("@tag", :find_all
     3  def_delegators("@tag", :search
    44   
    55  def initialize(tag) 
    66    @tag = tag 
     
    1515  end 
    1616   
    1717  def rails_method_hack 
    18     (tag = @tag.find(:tag => 'input', :attributes => { :name => '_method'})) && tag["value"] 
     18    (tag = @tag.find_element('input[_method]')) && tag["_method"] 
    1919  end 
    2020 
    2121end 
  • tarantula.orig/lib/relevance/tarantula/form_submission.rb

    old new  
    1717  end 
    1818   
    1919  def create_random_data_for(form, tag_selector) 
    20     form.find_all(tag_selector).inject({}) do |form_args, input| 
     20    form.search(tag_selector).inject({}) do |form_args, input| 
    2121      # TODO: test 
    2222      form_args[input['name']] = random_data(input) if input['name'] 
    2323      form_args 
     
    2525  end 
    2626 
    2727  def mutate_inputs(form) 
    28     create_random_data_for(form, :tag => 'input') 
     28    create_random_data_for(form, 'input') 
    2929  end 
    3030 
    3131  def mutate_text_areas(form) 
    32     create_random_data_for(form, :tag => 'textarea') 
     32    create_random_data_for(form, 'textarea') 
    3333  end 
    3434   
    3535  def mutate_selects(form) 
    36     form.find_all(:tag => 'select').inject({}) do |form_args, select| 
    37       options = select.find_all(:tag => 'option') 
     36    form.search('select').inject({}) do |form_args, select| 
     37      options = select.search('option') 
    3838      option = options.rand 
    3939      form_args[select['name']] = option['value']  
    4040      form_args 
     
    4646      when /amount/         : random_int 
    4747      when /_id$/           : random_whole_number 
    4848      when /uploaded_data/  : nil 
     49      when /^_method$/      : input['value'] 
    4950      when nil              : input['value'] 
    5051      else                    random_int 
    5152    end 
  • tarantula.orig/lib/relevance/tarantula/html_document_handler.rb

    old new  
     1require 'hpricot' 
     2 
    13class Relevance::Tarantula::HtmlDocumentHandler  
    24  extend Forwardable 
    35  def_delegators("@crawler", :queue_link, :queue_form) 
     
    1012  def html_doc_without_stderr_noise(html)   
    1113    body = nil 
    1214    Recording.stderr do 
    13       body = HTML::Document.new html 
     15      body = Hpricot html 
    1416    end        
    1517    body 
    1618  end 
     
    1921    url = result.url 
    2022    return unless response.html? 
    2123    body = html_doc_without_stderr_noise(response.body) 
    22     body.find_all(:tag=>'a').each do |tag| 
     24    body.search('a').each do |tag| 
    2325      queue_link(tag['href'], url) 
    2426    end 
    25     body.find_all(:tag=>'link').each do |tag| 
     27    body.search('link').each do |tag| 
    2628      queue_link(tag['href'], url) 
    2729    end 
    28     body.find_all(:tag =>'form').each do |form| 
     30    body.search('form').each do |form| 
    2931      form.attributes['action'] = url unless form.attributes['action'] 
    3032      queue_form(form, url) 
    3133    end