aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/alaveteli_text_masker_spec.rb7
-rw-r--r--spec/lib/basic_encoding_spec.rb24
2 files changed, 20 insertions, 11 deletions
diff --git a/spec/lib/alaveteli_text_masker_spec.rb b/spec/lib/alaveteli_text_masker_spec.rb
index f2d52c1cc..f8c22a849 100644
--- a/spec/lib/alaveteli_text_masker_spec.rb
+++ b/spec/lib/alaveteli_text_masker_spec.rb
@@ -31,10 +31,13 @@ describe AlaveteliTextMasker do
data.should == "There was a xxxxx called xxxxxxx, he wished that he was xxxx."
end
- it 'should handle multibyte characters correctly' do
+ it 'should handle multibyte characters in binary file types as binary data' do
data = 'á mouse'
+ if String.method_defined?(:encode)
+ data = data.force_encoding("ASCII-8BIT")
+ end
@regex_censor_rule.text = 'á'
- apply_masks!(data, "application/octet-stream", :censor_rules => @censor_rules).should == 'x mouse'
+ apply_masks!(data, "application/octet-stream", :censor_rules => @censor_rules).should == 'xx mouse'
end
it "should apply censor rules to HTML files" do
diff --git a/spec/lib/basic_encoding_spec.rb b/spec/lib/basic_encoding_spec.rb
index d77465ad8..6758d60a3 100644
--- a/spec/lib/basic_encoding_spec.rb
+++ b/spec/lib/basic_encoding_spec.rb
@@ -160,21 +160,24 @@ describe "convert_string_to_utf8" do
describe "when passed uninterpretable character data" do
- it "should return it as a utf8 string" do
+ it "should return it as a valid utf8 string with non-utf8 characters removed
+ and mark it as scrubbed" do
converted = convert_string_to_utf8 random_string
- converted.should == random_string
if String.method_defined?(:encode)
- converted.encoding.to_s.should == 'UTF-8'
+ converted.string.encoding.to_s.should == 'UTF-8'
+ converted.string.valid_encoding?.should == true
end
+ converted.scrubbed?.should == true
converted = convert_string_to_utf8 random_string,'UTF-8'
- converted.should == random_string
if String.method_defined?(:encode)
- converted.encoding.to_s.should == 'UTF-8'
+ converted.string.encoding.to_s.should == 'UTF-8'
+ converted.string.valid_encoding?.should == true
end
+ converted.scrubbed?.should == true
end
end
@@ -185,11 +188,13 @@ describe "convert_string_to_utf8" do
converted = convert_string_to_utf8 windows_1252_string
- converted.should == "DASH – DASH"
+ converted.string.should == "DASH – DASH"
if String.method_defined?(:encode)
- converted.encoding.to_s.should == 'UTF-8'
+ converted.string.encoding.to_s.should == 'UTF-8'
end
+ converted.scrubbed?.should == false
+
end
end
@@ -200,11 +205,12 @@ describe "convert_string_to_utf8" do
converted = convert_string_to_utf8 gb_18030_spam_string
- converted.should start_with("贵公司负责人")
+ converted.string.should start_with("贵公司负责人")
if String.method_defined?(:encode)
- converted.encoding.to_s.should == 'UTF-8'
+ converted.string.encoding.to_s.should == 'UTF-8'
end
+ converted.scrubbed?.should == false
end
end