Skip to content

Commit 667d426

Browse files
committed
avoid empty tokens in Diff output, fix split_into_parts
1 parent 2347f99 commit 667d426

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/coderay/scanners/diff.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def scan_tokens encoder, options
4545
if match = scan(/--- |\+\+\+ |=+|_+/)
4646
encoder.begin_line line_kind = :head
4747
encoder.text_token match, :head
48-
if match = scan(/.*?(?=$|[\t\n\x00]| \(revision)/)
48+
if match = scan(/.+?(?=$|[\t\n\x00]| \(revision)/)
4949
encoder.text_token match, :filename
5050
if options[:highlight_code] && match != '/dev/null'
5151
file_type = CodeRay::FileType.fetch(match, :text)

lib/coderay/tokens.rb

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def method_missing meth, options = {}
9393
# This method is used by @Scanner#tokenize@ when called with an Array
9494
# of source strings. The Diff encoder uses it for inline highlighting.
9595
def split_into_parts *sizes
96+
return Array.new(sizes.size) { Tokens.new } if size == 2 && first == ''
9697
parts = []
9798
opened = []
9899
content = nil

0 commit comments

Comments
 (0)