Project

General

Profile

Actions

Defect #7134

closed

is_binary_data uses wrong heuristic to decide if a string is binary

Added by Jérémy Lal over 13 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
SCM
Target version:
-
Start date:
2010-12-19
Due date:
% Done:

0%

Estimated time:
Resolution:
Duplicate
Affected version:

Description

The is_binary_data method, used in repositories_controller.rb#124, is :

def is_binary_data?
  ( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 ) unless empty?
end

Applied to the attached file :

str=''
File.open("test_color.sh", "r") { |f|
    str = f.read
}
(str.count("^ -~", "^\r\n") +0.0)/ str.length
=> 0.311345646437995

Which clearly is not < 0.3, so that file is downloaded instead of being displayed,
when one want to view it.


Files

test_color.sh (758 Bytes) test_color.sh Not binary file Jérémy Lal, 2010-12-19 14:00

Related issues

Is duplicate of Redmine - Defect #6256: Redmine considers non ASCII and UTF-16 text files as binary in SCMClosedToshi MARUYAMA2010-08-31

Actions
Actions

Also available in: Atom PDF