From 067c2ee2f5ae2b89d27b150510ab48af7eb0a10e Mon Sep 17 00:00:00 2001 From: "localhost.dev" Date: Sat, 13 Apr 2019 17:43:13 +0200 Subject: [PATCH 1/2] uses ruby's unicode_normalize method (added in ruby 2.2) DEPRECATION WARNING: ActiveSupport::Multibyte::Chars#normalize is deprecated and will be removed from Rails 6.1. Use #unicode_normalize(:nfkc) instead. --- lib/unidecoder.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/unidecoder.rb b/lib/unidecoder.rb index c525c816..5302305e 100644 --- a/lib/unidecoder.rb +++ b/lib/unidecoder.rb @@ -2,7 +2,6 @@ # Utilities for transliterating UTF-8 strings to ASCII. module Unidecoder - # Contains Unicode codepoints, loading as needed from YAML files. CODEPOINTS = Hash.new { |h, k| h[k] = YAML::load_file(File.expand_path("../unidecoder/data/#{k}.yml", __FILE__)) @@ -60,19 +59,10 @@ def in_yaml_file(character) "#{code_group(unpacked)}.yml (line #{grouped_point(unpacked) + 2})" end - def define_normalize(library = nil, &block) - return if method_defined? :normalize - begin - require library if library - define_method(:normalize, &block) - rescue LoadError - end + def normalize(str) + str.unicode_normalize end - define_normalize("unicode") {|str| Unicode.normalize_C(str)} - define_normalize("active_support") {|str| ActiveSupport::Multibyte::Chars.new(str).normalize(:c).to_s} - define_normalize {|str| str} - def decode_char(char) unpacked = char.unpack("U")[0] CODEPOINTS[code_group(unpacked)][grouped_point(unpacked)] From eb6794d593b7cd98a3bc5f021559675319ca2665 Mon Sep 17 00:00:00 2001 From: "localhost.dev" Date: Sat, 13 Apr 2019 17:50:51 +0200 Subject: [PATCH 2/2] safe_load yaml --- lib/unidecoder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/unidecoder.rb b/lib/unidecoder.rb index 5302305e..34bc5e7a 100644 --- a/lib/unidecoder.rb +++ b/lib/unidecoder.rb @@ -4,7 +4,7 @@ module Unidecoder # Contains Unicode codepoints, loading as needed from YAML files. CODEPOINTS = Hash.new { |h, k| - h[k] = YAML::load_file(File.expand_path("../unidecoder/data/#{k}.yml", __FILE__)) + h[k] = YAML.safe_load(File.read(File.expand_path("../unidecoder/data/#{k}.yml", __FILE__))) } unless defined?(CODEPOINTS) module StringExtensions