Skip to content

Commit

Permalink
Feature test for issue ruby-i18n#606 and disable the optimization if …
Browse files Browse the repository at this point in the history
…the bug is present
  • Loading branch information
byroot committed Feb 8, 2022
1 parent fb7095a commit ab0b6d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/i18n/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,21 @@ def load_rb(filename)

# Loads a YAML translations file. The data must have locales as
# toplevel keys.
def load_yml(filename)
begin
if YAML.respond_to?(:unsafe_load_file) # Psych 4.0 way
if YAML.respond_to?(:unsafe_load_file) && YAML.unsafe_load_file(File.expand_path("test_issue_606.yml", __dir__), symbolize_names: true).keys.first.encoding == Encoding::UTF_8
def load_yml(filename)
begin
[YAML.unsafe_load_file(filename, symbolize_names: true, freeze: true), true]
else
rescue TypeError, ScriptError, StandardError => e
raise InvalidLocaleData.new(filename, e.inspect)
end
end
else
def load_yml(filename)
begin
[YAML.load_file(filename), false]
rescue TypeError, ScriptError, StandardError => e
raise InvalidLocaleData.new(filename, e.inspect)
end
rescue TypeError, ScriptError, StandardError => e
raise InvalidLocaleData.new(filename, e.inspect)
end
end
alias_method :load_yaml, :load_yml
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/backend/test_issue_606.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
: ~

0 comments on commit ab0b6d9

Please sign in to comment.