lib/url_regexp/query.rb in url_regexp-0.1.1 vs lib/url_regexp/query.rb in url_regexp-0.1.2

- old
+ new

@@ -3,22 +3,22 @@ def initialize @queries = [] end def append(query) - if !query.nil? - @queries << query.to_s.split('&').reject(&:empty?) - end + return if query.nil? + @queries << query.to_s.split('&').reject(&:empty?) end def to_regexp_s - common_queries = @queries.reduce { |q1, q2| q1 & q2 } || [] + common_queries = @queries.reduce { |a, e| a & e } || [] + common_queries = common_queries.map { |q| Regexp.quote(q) } if 1 < common_queries.size - "\\?(#{common_queries.map { |q| Regexp.quote(q) }.permutation.to_a.map { |qs| "(.*&)?#{qs.join('.*&')}(&.*)?" }.join('|')})" + "\\?(#{common_queries.permutation.map { |qs| "(.*&)?#{qs.join('.*&')}(&.*)?" }.join('|')})" elsif 1 == common_queries.size - "\\?(.*&)?#{Regexp.quote(common_queries.first)}(&.*)?" + "\\?(.*&)?#{common_queries.first}(&.*)?" else - "(\\?.*)?" + '(\\?.*)?' end end end end