lib/ronin/formatting/extensions/sql/string.rb in ronin-support-0.5.0 vs lib/ronin/formatting/extensions/sql/string.rb in ronin-support-0.5.1

- old
+ new

@@ -38,14 +38,12 @@ # # @since 0.3.0 # def sql_escape(quotes=:single) case quotes - when :single - "'#{gsub(/'/,"''")}'" - when :double - "\"#{gsub(/"/,'""')}\"" + when :single then "'#{gsub(/'/,"''")}'" + when :double then "\"#{gsub(/"/,'""')}\"" else raise(ArgumentError,"invalid quoting style #{quotes.inspect}") end end @@ -78,20 +76,20 @@ # @example # "0x2f6574632f706173737764".sql_decode # # => "/etc/passwd" # def sql_decode - if ((self[0...2] == '0x') && (length % 2 == 0)) + if (start_with?('0x') && (length % 2 == 0)) raw = '' - self[2..-1].scan(/[0-9a-fA-F]{2}/).each do |hex_char| - raw << hex_char.hex.chr + self[2..-1].scan(/../) do |hex_char| + raw << hex_char.to_i(16).chr end return raw - elsif (self[0..0] == "'" && self[-1..-1] == "'") - self[1..-2].gsub("\\'","'").gsub("''","'") + elsif (start_with?("'") && end_with?("'")) + self[1..-2].gsub(/\\'|''/,"'") else return self end end @@ -117,13 +115,11 @@ # # @since 0.4.0 # def sql_inject if (start_with?("'") || start_with?('"') || start_with?('`')) - if self[0,1] == self[-1,1] - self[1..-2] - else - "#{self[1..-1]}--" + if self[0,1] == self[-1,1] then self[1..-2] + else "#{self[1..-1]}--" end else self end end