Skip to content

Commit

Permalink
Fixed unhandled encoding exception when using the 'log-pattern' option
Browse files Browse the repository at this point in the history
  • Loading branch information
Shlomi authored and majormoses committed Sep 23, 2017
1 parent 4353cac commit 1f625cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
- ruby 2.4 testing (@majormoses)

### Fixed
- Fixed unhandled encoding exception when using the `log-pattern` option (@jhshadi)
- PR template spelling "compatibility"

## [1.2.0] - 2017-07-04
Expand Down
19 changes: 12 additions & 7 deletions bin/check-log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,11 @@ def search_log
@log.seek(@bytes_to_skip, File::SEEK_SET) if @bytes_to_skip > 0
# #YELLOW
@log.each_line do |line|
line = encode_line(line)
if config[:log_pattern]
line = get_log_entry(line)
end

if config[:encode_utf16]
line = line.encode('UTF-16', invalid: :replace, replace: '')
end

line = line.encode('UTF-8', invalid: :replace, replace: '')
bytes_read += line.bytesize
if config[:case_insensitive]
m = line.downcase.match(config[:pattern].downcase) unless line.match(config[:exclude])
Expand Down Expand Up @@ -250,6 +246,8 @@ def get_log_entry(first_line)
log_entry = [first_line]

@log.each_line do |line|
line = encode_line(line)

if !line.match(config[:log_pattern])
log_entry.push(line)
else
Expand All @@ -258,7 +256,14 @@ def get_log_entry(first_line)
end
end

log_entry = log_entry.join('')
log_entry
log_entry.join('')
end

def encode_line(line)
if config[:encode_utf16]
line = line.encode('UTF-16', invalid: :replace, replace: '')
end

line.encode('UTF-8', invalid: :replace, replace: '')
end
end

0 comments on commit 1f625cf

Please sign in to comment.