lib/ronin/fuzzing/extensions/string.rb in ronin-support-0.4.1 vs lib/ronin/fuzzing/extensions/string.rb in ronin-support-0.5.0.rc1
- old
+ new
@@ -48,38 +48,38 @@
#
# @raise [TypeError]
# A given string set was not a String, Symbol or Enumerable.
# A given string set length was not an Integer or Enumerable.
#
- # @example Generate Strings with ranges of repeating sub-strings.
+ # @example Generate Strings with ranges of repeating sub-strings:
#
- # @example Generate Strings with three alpha chars and one numeric chars.
+ # @example Generate Strings with three alpha chars and one numeric chars:
# String.generate([:alpha, 3], :numeric) do |password|
# puts password
# end
#
- # @example Generate Strings with two to four alpha chars.
+ # @example Generate Strings with two to four alpha chars:
# String.generate([:alpha, 2..4]) do |password|
# puts password
# end
#
- # @example Generate Strings using alpha and punctuation chars.
+ # @example Generate Strings using alpha and punctuation chars:
# String.generate([Chars.alpha + Chars.punctuation, 4]) do |password|
# puts password
# end
#
- # @example Generate Strings from a custom char set.
+ # @example Generate Strings from a custom char set:
# String.generate([['a', 'b', 'c'], 3], [['1', '2', '3'], 3]) do |password|
# puts password
# end
#
- # @example Generate Strings containing known Strings.
+ # @example Generate Strings containing known Strings:
# String.generate("rock", [:numeric, 4]) do |password|
# puts password
# end
#
- # @example Generate Strings with ranges of repeating sub-strings.
+ # @example Generate Strings with ranges of repeating sub-strings:
# String.generate(['/AA', (1..100).step(5)]) do |path|
# puts path
# end
#
# @since 0.3.0
@@ -283,11 +283,11 @@
end
#
# Permutes over every possible mutation of the String.
#
- # @param [Hash{Regexp,String,Symbol => Symbol,#each}] mutations
+ # @param [Hash{Regexp,String,Symbol => Symbol,Enumerable}] mutations
# The patterns and substitutions to mutate the String with.
#
# @yield [mutant]
# The given block will be yielded every possible mutant String.
#
@@ -295,10 +295,14 @@
# A mutated String.
#
# @return [Enumerator]
# If no block is given, an Enumerator will be returned.
#
+ # @raise [TypeError]
+ # A mutation pattern was not a Regexp, String or Symbol.
+ # A mutation substitution was not a Symbol or Enumerable.
+ #
# @example
# "hello old dog".mutate('e' => ['3'], 'l' => ['1'], 'o' => ['0']) do |str|
# puts str
# end
#
@@ -320,9 +324,18 @@
when Symbol
Regexp.const_get(pattern.to_s.upcase)
else
raise(TypeError,"cannot convert #{pattern.inspect} to a Regexp")
end
+
+ mutation = case mutation
+ when Symbol
+ Ronin::Fuzzing[mutation]
+ when Enumerable
+ mutation
+ else
+ raise(TypeError,"mutation #{mutation.inspect} must be a Symbol or Enumerable")
+ end
scanner = StringScanner.new(self)
while scanner.scan_until(pattern)
length = scanner.matched_size