diff options
author | Francis Irving <francis@mysociety.org> | 2010-03-20 22:13:33 +0000 |
---|---|---|
committer | Francis Irving <francis@mysociety.org> | 2010-03-20 22:13:33 +0000 |
commit | 0e8f9db5038c5dc7e41d9f5dbca531978456c4e9 (patch) | |
tree | 38615430d685a7072f7f254dfc73dbe5483ebeb5 | |
parent | 09449e0cb034134290a90c80498d591a831c2d02 (diff) | |
parent | d29fd88e3c54a5a5a94b29d16cb46dd859b59e05 (diff) |
Merge commit 'peter/pdftk-silent-failure'
-rw-r--r-- | app/models/incoming_message.rb | 4 | ||||
-rw-r--r-- | spec/fixtures/psni.pdf | bin | 0 -> 48057 bytes | |||
-rw-r--r-- | spec/models/incoming_message_spec.rb | 7 |
3 files changed, 9 insertions, 2 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 8ea4f0fb7..29dfb4089 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -543,7 +543,7 @@ class IncomingMessage < ActiveRecord::Base uncompressed_text = child.read() end # if we managed to uncompress the PDF... - if !uncompressed_text.nil? + if !uncompressed_text.nil? && !uncompressed_text.empty? # then censor stuff (making a copy so can compare again in a bit) censored_uncompressed_text = uncompressed_text.dup self._binary_mask_stuff_internal!(censored_uncompressed_text) @@ -556,7 +556,7 @@ class IncomingMessage < ActiveRecord::Base child.close_write() recompressed_text = child.read() end - if !recompressed_text.nil? + if !recompressed_text.nil? && !recompressed_text.empty? text[0..-1] = recompressed_text # [0..-1] makes it change the 'text' string in place end end diff --git a/spec/fixtures/psni.pdf b/spec/fixtures/psni.pdf Binary files differnew file mode 100644 index 000000000..daca3f4ec --- /dev/null +++ b/spec/fixtures/psni.pdf diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 0cfdeac3a..35e9b3a2b 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -174,6 +174,13 @@ describe IncomingMessage, " when censoring data" do masked_text.should match(/xxx@xxx.xxx.xx/) end + it "should not produce zero length output if pdftk silently fails" do + orig_pdf = load_file_fixture('psni.pdf') + pdf = orig_pdf.dup + @im.binary_mask_stuff!(pdf, "application/pdf") + pdf.should_not == "" + end + it "should apply censor rules to HTML files" do data = @test_data.dup @im.html_mask_stuff!(data) |