aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/censor_rule.rb7
-rw-r--r--spec/models/censor_rule_spec.rb24
2 files changed, 20 insertions, 11 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb
index 4548a3a71..4e96dc55a 100644
--- a/app/models/censor_rule.rb
+++ b/app/models/censor_rule.rb
@@ -43,10 +43,6 @@ class CensorRule < ActiveRecord::Base
end
end
- def binary_replacement
- self.text.gsub(/./, 'x')
- end
-
def apply_to_text!(text)
if text.nil?
return nil
@@ -59,7 +55,8 @@ class CensorRule < ActiveRecord::Base
if binary.nil?
return nil
end
- binary.gsub!(self.text, self.binary_replacement)
+ to_replace = regexp? ? Regexp.new(self.text, Regexp::MULTILINE) : self.text
+ binary.gsub!(to_replace){ |match| match.gsub(/./, 'x') }
end
def for_admin_column
diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb
index 6b48ac317..de9651f01 100644
--- a/spec/models/censor_rule_spec.rb
+++ b/spec/models/censor_rule_spec.rb
@@ -35,18 +35,18 @@ describe CensorRule, "substituting things" do
@censor_rule.text = "--PRIVATE.*--PRIVATE"
@censor_rule.replacement = "--REMOVED\nHidden private info\n--REMOVED"
@censor_rule.regexp = true
- end
-
- it "replaces with the regexp" do
- body =
+ @body =
<<BODY
Some public information
--PRIVATE
Some private information
--PRIVATE
BODY
- @censor_rule.apply_to_text!(body)
- body.should ==
+ end
+
+ it "replaces the regexp with the replacement text when applied to text" do
+ @censor_rule.apply_to_text!(@body)
+ @body.should ==
<<BODY
Some public information
--REMOVED
@@ -55,6 +55,18 @@ Hidden private info
BODY
end
+ it "replaces the regexp with the same number of 'x' characters as the text replaced
+ when applied to binary" do
+ @censor_rule.apply_to_binary!(@body)
+ @body.should ==
+<<BODY
+Some public information
+xxxxxxxxx
+xxxxxxxxxxxxxxxxxxxxxxxx
+xxxxxxxxx
+BODY
+ end
+
end
end