Permalink
Browse files

Specify UTF-8 as external encoding when opening public suffix data file.

This fixes parsing for Ruby 1.9
  • Loading branch information...
1 parent 1416b8b commit 2b40215fc5c17088190800281474fd29db0f39cc @enricob enricob committed Jun 21, 2010
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/domainatrix/domain_parser.rb
View
9 lib/domainatrix/domain_parser.rb
@@ -10,7 +10,14 @@ def initialize(file_name)
end
def read_dat_file(file_name)
- File.readlines(file_name).each do |line|
+ # If we're in 1.9, make sure we're opening it in UTF-8
+ if RUBY_VERSION >= '1.9'
+ dat_file = File.open(file_name, "r:UTF-8")
+ else
+ dat_file = File.open(file_name)
+ end
+
+ dat_file.each_line do |line|
line = line.strip
unless (line =~ /\/\//) || line.empty?
parts = line.split(".").reverse

0 comments on commit 2b40215

Please sign in to comment.