Changeset 318

Show
Ignore:
Timestamp:
05/05/08 03:20:27 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

Raising 'binary file' when trying to index binary file as plain text

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/picolena/templates/lib/plain_text_extractors/plain_text.rb

    r312 r318  
    44  aka "plain text file" 
    55  with {|source| 
    6     if File.plain_text?(source) then 
    7       encoding=File.encoding(source) 
    8       if encoding.empty? then 
    9          File.read(source) 
    10       else 
    11          %x{iconv -f #{encoding} -t utf8  "#{source}" 2>/dev/null} 
    12       end 
     6    raise "Binary file : #{source}" unless File.plain_text?(source) 
     7    encoding=File.encoding(source) 
     8    if encoding.empty? then 
     9      File.read(source) 
    1310    else 
    14       nil 
     11      %x{iconv -f #{encoding} -t utf8  "#{source}" 2>/dev/null} 
    1512    end 
    1613  } 
  • trunk/lib/picolena/templates/spec/models/plain_text_extractor_spec.rb

    r312 r318  
    3030 
    3131  it "should not extract content of binary files" do 
    32     PlainTextExtractor.extract_content_from("spec/test_dirs/indexed/others/BIN_FILE_WITHOUT_EXTENSION").should be_blank 
     32    bin_file="spec/test_dirs/indexed/others/BIN_FILE_WITHOUT_EXTENSION" 
     33    lambda{PlainTextExtractor.extract_content_from(bin_file)}.should raise_error(RuntimeError, "Binary file : "<<bin_file) 
    3334  end 
    3435end