aboutsummaryrefslogtreecommitdiffstats
path: root/lib/alaveteli_text_masker.rb
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-06-24 11:19:43 +0100
committerGareth Rees <gareth@mysociety.org>2015-06-24 11:19:43 +0100
commit2cce1794a4d9d2c42b83bab8a693900e8ca23ebc (patch)
tree7408a04d5ac0963ec2defbbf7d4955cff7cd62b5 /lib/alaveteli_text_masker.rb
parented6b256539e0dcaa3764951d90e2dc599a8acddd (diff)
parent54ba7a4fa232ad3b57310551b9a5e19d72060abe (diff)
Merge branch 'develop' into release-22-develop
Diffstat (limited to 'lib/alaveteli_text_masker.rb')
-rw-r--r--lib/alaveteli_text_masker.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/alaveteli_text_masker.rb b/lib/alaveteli_text_masker.rb
index 3c2bcf825..49dd15ae5 100644
--- a/lib/alaveteli_text_masker.rb
+++ b/lib/alaveteli_text_masker.rb
@@ -8,6 +8,21 @@ module AlaveteliTextMasker
'image/bmp',
'application/zip' ]
+ TextMask = [ 'text/css',
+ 'text/csv',
+ 'text/html',
+ 'text/plain',
+ 'text/rfc822-headers',
+ 'text/rtf',
+ 'text/tab-separated-values',
+ 'text/x-c',
+ 'text/x-diff',
+ 'text/x-fortran',
+ 'text/x-mail',
+ 'text/xml',
+ 'text/x-pascal',
+ 'text/x-vcard' ]
+
# Replaces all email addresses in (possibly binary) data
# Also applies custom masks and censor items
def apply_masks!(text, content_type, options = {})
@@ -19,7 +34,7 @@ module AlaveteliTextMasker
case content_type
when *DoNotBinaryMask
# do nothing
- when 'text/html'
+ when *TextMask
apply_text_masks!(text, options)
when 'application/pdf'
apply_pdf_masks!(text, options)
@@ -79,7 +94,7 @@ module AlaveteliTextMasker
# Replace text in place
def apply_binary_masks!(text, options = {})
# Keep original size, so can check haven't resized it
- orig_size = text.mb_chars.size
+ orig_size = text.size
# Replace ASCII email addresses...
text.gsub!(MySociety::Validate.email_find_regexp) do |email|
@@ -114,7 +129,7 @@ module AlaveteliTextMasker
# Replace censor items
censor_rules = options[:censor_rules] || []
censor_rules.each{ |censor_rule| censor_rule.apply_to_binary!(text) }
- raise "internal error in apply_binary_masks!" if text.mb_chars.size != orig_size
+ raise "internal error in apply_binary_masks!" if text.size != orig_size
return text
end