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 1 1 class Relevance::Tarantula::Form 2 2 extend Forwardable 3 def_delegators("@tag", : find_all)3 def_delegators("@tag", :search) 4 4 5 5 def initialize(tag) 6 6 @tag = tag … … 15 15 end 16 16 17 17 def rails_method_hack 18 (tag = @tag.find (:tag => 'input', :attributes => { :name => '_method'})) && tag["value"]18 (tag = @tag.find_element('input[_method]')) && tag["_method"] 19 19 end 20 20 21 21 end -
tarantula.orig/lib/relevance/tarantula/form_submission.rb
old new 17 17 end 18 18 19 19 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| 21 21 # TODO: test 22 22 form_args[input['name']] = random_data(input) if input['name'] 23 23 form_args … … 25 25 end 26 26 27 27 def mutate_inputs(form) 28 create_random_data_for(form, :tag =>'input')28 create_random_data_for(form, 'input') 29 29 end 30 30 31 31 def mutate_text_areas(form) 32 create_random_data_for(form, :tag =>'textarea')32 create_random_data_for(form, 'textarea') 33 33 end 34 34 35 35 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') 38 38 option = options.rand 39 39 form_args[select['name']] = option['value'] 40 40 form_args … … 46 46 when /amount/ : random_int 47 47 when /_id$/ : random_whole_number 48 48 when /uploaded_data/ : nil 49 when /^_method$/ : input['value'] 49 50 when nil : input['value'] 50 51 else random_int 51 52 end -
tarantula.orig/lib/relevance/tarantula/html_document_handler.rb
old new 1 require 'hpricot' 2 1 3 class Relevance::Tarantula::HtmlDocumentHandler 2 4 extend Forwardable 3 5 def_delegators("@crawler", :queue_link, :queue_form) … … 10 12 def html_doc_without_stderr_noise(html) 11 13 body = nil 12 14 Recording.stderr do 13 body = H TML::Document.newhtml15 body = Hpricot html 14 16 end 15 17 body 16 18 end … … 19 21 url = result.url 20 22 return unless response.html? 21 23 body = html_doc_without_stderr_noise(response.body) 22 body. find_all(:tag=>'a').each do |tag|24 body.search('a').each do |tag| 23 25 queue_link(tag['href'], url) 24 26 end 25 body. find_all(:tag=>'link').each do |tag|27 body.search('link').each do |tag| 26 28 queue_link(tag['href'], url) 27 29 end 28 body. find_all(:tag =>'form').each do |form|30 body.search('form').each do |form| 29 31 form.attributes['action'] = url unless form.attributes['action'] 30 32 queue_form(form, url) 31 33 end
