lib/redis_scanner/rule.rb in redis_scanner-0.1.4 vs lib/redis_scanner/rule.rb in redis_scanner-0.1.5
- old
+ new
@@ -1,5 +1,7 @@
+# -*- encoding : utf-8 -*-
+
module RedisScanner
class Rule
PRESET_RULES = [
[/(:\d+:)/, ":<id>:"],
[/(:\w{8}-\w{4}-\w{4}-\w{4}-\w{12}:)/, ":<uuid>:"],
@@ -12,15 +14,31 @@
def initialize
@rules = PRESET_RULES
end
def extract_pattern(key)
+ key = force_valid_key(key)
@rules.each do |rule, replacer|
if m = rule.match(key)
key = key.sub(m[1], replacer)
break
end
end
key
+ end
+
+ private
+
+ def force_valid_key(key)
+ if key.valid_encoding?
+ key
+ else
+ key.size.times do |index|
+ unless key[index].valid_encoding?
+ key[index] = "?"
+ end
+ end
+ key
+ end
end
end
end
\ No newline at end of file