Skip to content

Commit

Permalink
Fix unknown encoding (dj2#12)
Browse files Browse the repository at this point in the history
Verify that the given encoding is valid before using.
  • Loading branch information
bulinutza authored and dj2 committed Nov 5, 2018
1 parent 78bebdb commit ea3ee5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/ruby-rtf/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@ def handle_control(name, val, src, current_pos)
case(name)
when :rtf then ;
when :deff then @doc.default_font = val
when :ansicpg then self.encoding = "windows-#{val}"
when :ansicpg then
begin
# Set the encoding if it's valid
Encoding.find("windows-#{val}")
self.encoding = "windows-#{val}"
rescue => e
# ignore
end

when *[:ansi, :mac, :pc, :pca] then @doc.character_set = name
when :fonttbl then current_pos = parse_font_table(src, current_pos)
when :colortbl then current_pos = parse_colour_table(src, current_pos)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-rtf/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Main namespace of the RTF parser
module RubyRTF
# Current library version
VERSION = '0.0.4'
VERSION = '0.0.5'
end

0 comments on commit ea3ee5b

Please sign in to comment.