Class: ApiHammer::Filtration::FormEncoded
- Defined in:
- lib/api_hammer/filtration/form_encoded.rb
Instance Method Summary collapse
- #filter ⇒ Object
-
#initialize(string, options = {}) ⇒ FormEncoded
constructor
A new instance of FormEncoded.
Constructor Details
#initialize(string, options = {}) ⇒ FormEncoded
Returns a new instance of FormEncoded.
6 7 8 9 |
# File 'lib/api_hammer/filtration/form_encoded.rb', line 6 def initialize(string, = {}) @string = string @options = end |
Instance Method Details
#filter ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/api_hammer/filtration/form_encoded.rb', line 11 def filter ss = StringScanner.new(@string) filtered = '' while !ss.eos? if ss.scan(/[&;]/) filtered << ss[0] end if ss.scan(/[^&;]+/) kv = ss[0] key, _ = kv.split('=', 2) parsed_key = CGI::unescape(key) if [*@options[:filter_keys]].any? { |fk| parsed_key =~ /(\A|[\[\]])#{Regexp.escape(fk)}(\z|[\[\]])/ } filtered << [key, '[FILTERED]'].join('=') else filtered << ss[0] end end end filtered end |