From 2f14be09b57b81ec0a472c04746b440215441ffd Mon Sep 17 00:00:00 2001 From: erwanlr Date: Mon, 11 Mar 2013 17:21:09 +0100 Subject: [PATCH] All hacks moved to hacks.rb --- lib/common/common_helper.rb | 36 ------------------------------------ lib/common/hacks.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/common/common_helper.rb b/lib/common/common_helper.rb index bc96267f..b6518e2d 100644 --- a/lib/common/common_helper.rb +++ b/lib/common/common_helper.rb @@ -100,32 +100,6 @@ def get_equal_string_end(stringarray = ['']) already_found end -# Since ruby 1.9.2, URI::escape is obsolete -# See http://rosettacode.org/wiki/URL_encoding#Ruby and http://www.ruby-forum.com/topic/207489 -if RUBY_VERSION >= '1.9.2' - module URI - def self.escape(str) - URI.encode_www_form_component(str).gsub('+', '%20') - end - end -end - -if RUBY_VERSION < '1.9' - class Array - # Fix for grep with symbols in ruby <= 1.8.7 - def _grep_(regexp) - matches = [] - self.each do |value| - value = value.to_s - matches << value if value.match(regexp) - end - matches - end - - alias_method :grep, :_grep_ - end -end - # loading the updater require_files_from_directory(UPDATER_LIB_DIR) @updater = UpdaterFactory.get_updater(ROOT_DIR) @@ -173,13 +147,3 @@ def get_metasploit_url(module_path) module_path = module_path.sub(/^\//, '') "http://www.metasploit.com/modules/#{module_path}" end - -# Override for puts to enable logging -def puts(o = '') - # remove color for logging - if o.respond_to?('gsub') - temp = o.gsub(/\e\[\d+m(.*)?\e\[0m/, '\1') - File.open(LOG_FILE, 'a+') { |f| f.puts(temp) } - end - super(o) -end diff --git a/lib/common/hacks.rb b/lib/common/hacks.rb index cf7a80b7..0a2dcda7 100644 --- a/lib/common/hacks.rb +++ b/lib/common/hacks.rb @@ -8,3 +8,39 @@ module Nokogiri end end end + +# Since ruby 1.9.2, URI::escape is obsolete +# See http://rosettacode.org/wiki/URL_encoding#Ruby and http://www.ruby-forum.com/topic/207489 +if RUBY_VERSION >= '1.9.2' + module URI + def self.escape(str) + URI.encode_www_form_component(str).gsub('+', '%20') + end + end +end + +if RUBY_VERSION < '1.9' + class Array + # Fix for grep with symbols in ruby <= 1.8.7 + def _grep_(regexp) + matches = [] + self.each do |value| + value = value.to_s + matches << value if value.match(regexp) + end + matches + end + + alias_method :grep, :_grep_ + end +end + +# Override for puts to enable logging +def puts(o = '') + # remove color for logging + if o.respond_to?('gsub') + temp = o.gsub(/\e\[\d+m(.*)?\e\[0m/, '\1') + File.open(LOG_FILE, 'a+') { |f| f.puts(temp) } + end + super(o) +end