From b460cb7dae6cc7f272e9840c6c1afe26efc00ed6 Mon Sep 17 00:00:00 2001 From: Adrien Rey-Jarthon Date: Sun, 9 Apr 2023 16:46:31 +0200 Subject: [PATCH] restore unicode_normalize_kc as a deprecated method (#504) As discussed in https://github.com/sporkmonger/addressable/pull/492#discussion_r1157346135, this change restores `unicode_normalize_kc` as a deprecated method (in case some people where using it). Example of the produced warning: ``` NOTE: Addressable::IDNA.unicode_normalize_kc is deprecated; use String#unicode_normalize(:nfkc) instead. It will be removed on or after 2023-04. Addressable::IDNA.unicode_normalize_kc called from benchmark/unicode_normalize.rb:17. ``` --- benchmark/unicode_normalize.rb | 2 +- lib/addressable/idna/native.rb | 10 ++++++++++ lib/addressable/idna/pure.rb | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/benchmark/unicode_normalize.rb b/benchmark/unicode_normalize.rb index 760f249f..967f7bb5 100644 --- a/benchmark/unicode_normalize.rb +++ b/benchmark/unicode_normalize.rb @@ -2,7 +2,7 @@ # frozen_string_literal: true. require "benchmark" -require "addressable/idna/pure.rb" +require_relative "../lib/addressable/idna/pure.rb" require "idn" value = "fiᆵリ宠퐱卄.com" diff --git a/lib/addressable/idna/native.rb b/lib/addressable/idna/native.rb index b225e1c3..a718364f 100644 --- a/lib/addressable/idna/native.rb +++ b/lib/addressable/idna/native.rb @@ -29,6 +29,16 @@ def self.punycode_decode(value) IDN::Punycode.decode(value.to_s) end + class << self + # @deprecated Use {String#unicode_normalize(:nfkc)} instead + def unicode_normalize_kc(value) + value.to_s.unicode_normalize(:nfkc) + end + + extend Gem::Deprecate + deprecate :unicode_normalize_kc, "String#unicode_normalize(:nfkc)", 2023, 4 + end + def self.to_ascii(value) value.to_s.split('.', -1).map do |segment| if segment.size > 0 && segment.size < 64 diff --git a/lib/addressable/idna/pure.rb b/lib/addressable/idna/pure.rb index ae09ec66..3d6ffbad 100644 --- a/lib/addressable/idna/pure.rb +++ b/lib/addressable/idna/pure.rb @@ -112,6 +112,16 @@ def self.to_unicode(input) output end + class << self + # @deprecated Use {String#unicode_normalize(:nfkc)} instead + def unicode_normalize_kc(value) + value.to_s.unicode_normalize(:nfkc) + end + + extend Gem::Deprecate + deprecate :unicode_normalize_kc, "String#unicode_normalize(:nfkc)", 2023, 4 + end + ## # Unicode aware downcase method. #