summaryrefslogtreecommitdiff
path: root/dev-ruby/domain_name/files/domain_name-0.5.20190701-drop-unf.patch
blob: d9b6c4df65a5835a36a6ad8eca5d252e592237b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
https://github.com/knu/ruby-domain_name/pull/11
(see also https://github.com/knu/ruby-domain_name/pull/22)

From 28db4ddb42adb827fc54935a6308bae03d7e8e6c Mon Sep 17 00:00:00 2001
From: tayler1 <mtayler@gmx.com>
Date: Sat, 4 Feb 2017 18:20:07 +0300
Subject: [PATCH 1/3] Removed unf dependency for ruby > 2.2

--- a/domain_name.gemspec
+++ b/domain_name.gemspec
@@ -28,7 +28,7 @@ Suffix List.
     "README.md"
   ]
 
-  gem.add_runtime_dependency("unf", ["< 1.0.0", ">= 0.0.5"])
+  gem.add_runtime_dependency("unf", ["< 1.0.0", ">= 0.0.5"]) if RUBY_VERSION < "2.2"
   gem.add_development_dependency("test-unit", "~> 2.5.5")
   gem.add_development_dependency("bundler", [">= 1.2.0"])
   gem.add_development_dependency("rake", [">= 0.9.2.2", *("< 11" if RUBY_VERSION < "1.9")])
--- a/lib/domain_name.rb
+++ b/lib/domain_name.rb
@@ -8,7 +8,7 @@
 require 'domain_name/version'
 require 'domain_name/punycode'
 require 'domain_name/etld_data'
-require 'unf'
+require 'unf' if RUBY_VERSION < '2.2'
 require 'ipaddr'
 
 # Represents a domain name ready for extracting its registered domain
@@ -286,7 +286,11 @@ class << self
     # Normalizes a _domain_ using the Punycode algorithm as necessary.
     # The result will be a downcased, ASCII-only string.
     def normalize(domain)
-      DomainName::Punycode.encode_hostname(domain.chomp(DOT).to_nfc).downcase
+      if RUBY_VERSION >= '2.2'
+        DomainName::Punycode.encode_hostname(domain.chomp(DOT).unicode_normalize).downcase
+      else
+        DomainName::Punycode.encode_hostname(domain.chomp(DOT).to_nfc).downcase
+      end
     end
   end
 end
--- a/test/test_domain_name-punycode.rb
+++ b/test/test_domain_name-punycode.rb
@@ -91,7 +91,12 @@ class TestDomainName < Test::Unit::TestCase
         '-> $1.00 <--']
     ].each { |title, cps, punycode|
       assert_equal punycode, DomainName::Punycode.encode(cps.pack('U*')), title
-      assert_equal cps.pack('U*').to_nfc, DomainName::Punycode.decode(punycode), title
+      cps_norm = if RUBY_VERSION >= '2.2'
+          cps.pack('U*').unicode_normalize
+        else
+          cps.pack('U*').to_nfc
+        end
+      assert_equal cps_norm, DomainName::Punycode.decode(punycode), title
     }
   end
 end

From 9d2912428799cd860d96c24d51292f2b03e857e2 Mon Sep 17 00:00:00 2001
From: tayler1 <mtayler@gmx.com>
Date: Mon, 6 Feb 2017 01:46:03 +0300
Subject: [PATCH 2/3] fix

--- a/lib/domain_name.rb
+++ b/lib/domain_name.rb
@@ -8,8 +8,12 @@
 require 'domain_name/version'
 require 'domain_name/punycode'
 require 'domain_name/etld_data'
-require 'unf' if RUBY_VERSION < '2.2'
 require 'ipaddr'
+if RUBY_VERSION < '2.2'
+  require 'unf'
+else
+  require 'unicode_normalize/normalize'
+end
 
 # Represents a domain name ready for extracting its registered domain
 # and TLD.
@@ -285,11 +289,15 @@ def inspect
   class << self
     # Normalizes a _domain_ using the Punycode algorithm as necessary.
     # The result will be a downcased, ASCII-only string.
-    def normalize(domain)
-      if RUBY_VERSION >= '2.2'
-        DomainName::Punycode.encode_hostname(domain.chomp(DOT).unicode_normalize).downcase
-      else
-        DomainName::Punycode.encode_hostname(domain.chomp(DOT).to_nfc).downcase
+    if RUBY_VERSION >= '2.2'
+      def normalize(domain)
+        domain.chomp!(DOT)        
+        DomainName::Punycode.encode_hostname(domain.unicode_normalize).downcase
+      end
+    else
+      def normalize(domain)
+        domain.chomp!(DOT)
+        DomainName::Punycode.encode_hostname(domain.to_nfc).downcase
       end
     end
   end

From 6d76a14ba3b7c42d4fd3f4fab30c0099ffc51c2b Mon Sep 17 00:00:00 2001
From: tayler1 <mtayler@gmx.com>
Date: Mon, 6 Feb 2017 02:35:55 +0300
Subject: [PATCH 3/3] Fix frozen string

--- a/lib/domain_name.rb
+++ b/lib/domain_name.rb
@@ -291,13 +291,11 @@ class << self
     # The result will be a downcased, ASCII-only string.
     if RUBY_VERSION >= '2.2'
       def normalize(domain)
-        domain.chomp!(DOT)        
-        DomainName::Punycode.encode_hostname(domain.unicode_normalize).downcase
+        DomainName::Punycode.encode_hostname(domain.chomp(DOT).unicode_normalize).downcase
       end
     else
       def normalize(domain)
-        domain.chomp!(DOT)
-        DomainName::Punycode.encode_hostname(domain.to_nfc).downcase
+        DomainName::Punycode.encode_hostname(domain.chomp(DOT).to_nfc).downcase
       end
     end
   end