Skip to content

Commit

Permalink
restore unicode_normalize_kc as a deprecated method (#504)
Browse files Browse the repository at this point in the history
As discussed in #492 (comment), 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.
```
  • Loading branch information
jarthod authored Apr 9, 2023
1 parent 68c60e3 commit b460cb7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion benchmark/unicode_normalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions lib/addressable/idna/native.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/addressable/idna/pure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down

0 comments on commit b460cb7

Please sign in to comment.