Skip to content

Commit

Permalink
Only double check binary mime type when lazy loading blob
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Aug 20, 2012
1 parent 620150d commit f8df871
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/linguist/blob_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def detect_encoding
@detect_encoding ||= CharlockHolmes::EncodingDetector.new.detect(data) if data
end

# Public: Is the blob binary according to its mime type
# Internal: Is the blob binary according to its mime type
#
# Return true or false
def binary_mime_type?
Expand Down Expand Up @@ -260,8 +260,14 @@ def indexable?
# Returns a Language or nil if none is detected
def language
return @language if defined? @language
data_loader = lambda { binary_mime_type? ? "" : data }
@language = Language.detect(name.to_s, data_loader, mode)

if defined?(@data) && @data.is_a?(String)
data = @data
else
data = lambda { binary_mime_type? ? "" : self.data }
end

@language = Language.detect(name.to_s, data, mode)
end

# Internal: Get the lexer of the blob.
Expand Down

0 comments on commit f8df871

Please sign in to comment.