module Acunetix module Cleanup private # Convert HTML in the text to Textile format def cleanup_html(source) result = source.dup format_table(result) result.gsub!(/"/, '"') result.gsub!(/&/, '&') result.gsub!(/</, '<') result.gsub!(/>/, '>') result.gsub!(/(.*?)<\/h[0-9]>/) { "\n\n*#{$1.strip}*\n\n" } result.gsub!(/(.*?)<\/b>/) { "*#{$1.strip}*" } result.gsub!(//, "\n") result.gsub!(/|<\/div>/, '') result.gsub!(/(.*?)<\/a>/m, '\1') result.gsub!(/(.*?)<\/font>/m, '\1') result.gsub!(/

(.*?)<\/h2>/) { "*#{$1.strip}*" } result.gsub!(/(.*?)<\/i>/, '\1') result.gsub!(/(.*?)<\/p>/) { "\np. #{$1.strip}\n" } result.gsub!(/(.*?)<\/pre><\/code>/m){|m| "\n\nbc.. #{$1.strip}\n\np. \n" } result.gsub!(/(.*?)<\/code>/) { "@#{$1.strip}@" } result.gsub!(/(.*?)<\/pre>/m){|m| "\n\nbc.. #{$1.strip}\n\np. \n" } result.gsub!(/([\s\S]*?)<\/li>/m){"\n* #{$1.strip}"} result.gsub!(/
    ([\s\S]*?)<\/ul>/m){ "#{$1.strip}\n" } result.gsub!(/(
      )|(<\/ul>|(
        )|(<\/ol>))/, "\n") result.gsub!(/
      1. /, "\n* ") result.gsub!(/<\/li>/, "\n") result.gsub!(/(.*?)<\/strong>/) { "*#{$1.strip}*" } result.gsub!(/(.*?)<\/span>/m){"#{$1.strip}\n"} result end # Replace periods for commas as decimals def cleanup_decimals(source) result = source.dup result.gsub!(/([0-9])\,([0-9])/, '\1.\2') result end def format_table(str) return unless str.include?('') str.gsub!(/[\s\S]*<\/table>/) do |table| rows = [''] table.scan(/[\s\S]*?<\/tr>/).each do |tr| row = '|' tr.scan(/[\s\S]*?<\/td>/).each do |data| header = rows.empty? ? '_. ' : '' row << "#{header}#{data.gsub(/|<\/td>/, '')}|" end rows << row end rows.join("\n") end end # Some of the values have embedded HTML conent that we need to strip def tags_with_html_content [:details, :description, :detailed_information, :impact, :recommendation] end def tags_with_commas [:cvss3_score, :cvss3_tempscore, :cvss3_envscore] end end end