idn-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +17 -0
- data/LICENSE +247 -0
- data/NOTICE +5 -0
- data/README +193 -0
- data/Rakefile +60 -0
- data/ext/extconf.rb +56 -0
- data/ext/idn.c +59 -0
- data/ext/idn.h +59 -0
- data/ext/idna.c +164 -0
- data/ext/punycode.c +160 -0
- data/ext/stringprep.c +183 -0
- data/test/tc_Idna.rb +273 -0
- data/test/tc_Punycode.rb +188 -0
- data/test/tc_Stringprep.rb +81 -0
- data/test/ts_IDN.rb +31 -0
- metadata +83 -0
data/test/tc_Punycode.rb
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
# Unit tests for IDN::Punycode.
|
2
|
+
#
|
3
|
+
# Copyright (c) 2005 Erik Abele. All rights reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# Please see the file called LICENSE for further details.
|
8
|
+
#
|
9
|
+
# You may also obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# * http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# This software is OSI Certified Open Source Software.
|
20
|
+
# OSI Certified is a certification mark of the Open Source Initiative.
|
21
|
+
|
22
|
+
require 'test/unit'
|
23
|
+
require 'idn'
|
24
|
+
|
25
|
+
class Test_Punycode < Test::Unit::TestCase
|
26
|
+
include IDN
|
27
|
+
|
28
|
+
# RFC3492 test vectors, taken from RFC3492 (7.1 Sample Strings):
|
29
|
+
# http://www.ietf.org/rfc/rfc3492.txt
|
30
|
+
#
|
31
|
+
# Modifications:
|
32
|
+
# - correction of an obviously wrong uppercase character in case I
|
33
|
+
|
34
|
+
TESTCASES_RFC3492 = {
|
35
|
+
'A' => [
|
36
|
+
[ 0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643,
|
37
|
+
0x0644, 0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A,
|
38
|
+
0x061F ].pack('U*'),
|
39
|
+
'egbpdaj6bu4bxfgehfvwxn'
|
40
|
+
],
|
41
|
+
|
42
|
+
'B' => [
|
43
|
+
[ 0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D,
|
44
|
+
0x6587 ].pack('U*'),
|
45
|
+
'ihqwcrb4cv8a8dqg056pqjye'
|
46
|
+
],
|
47
|
+
|
48
|
+
'C' => [
|
49
|
+
[ 0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D,
|
50
|
+
0x6587 ].pack('U*'),
|
51
|
+
'ihqwctvzc91f659drss3x8bo0yb'
|
52
|
+
],
|
53
|
+
|
54
|
+
'D' => [
|
55
|
+
[ 0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073,
|
56
|
+
0x0074, 0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076,
|
57
|
+
0x00ED, 0x010D, 0x0065, 0x0073, 0x006B, 0x0079 ].pack('U*'),
|
58
|
+
'Proprostnemluvesky-uyb24dma41a'
|
59
|
+
],
|
60
|
+
|
61
|
+
'E' => [
|
62
|
+
[ 0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5,
|
63
|
+
0x05D8, 0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9,
|
64
|
+
0x05DD, 0x05E2, 0x05D1, 0x05E8, 0x05D9, 0x05EA ].pack('U*'),
|
65
|
+
'4dbcagdahymbxekheh6e0a7fei0b'
|
66
|
+
],
|
67
|
+
|
68
|
+
'F' => [
|
69
|
+
[ 0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928,
|
70
|
+
0x094D, 0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902,
|
71
|
+
0x0928, 0x0939, 0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938,
|
72
|
+
0x0915, 0x0924, 0x0947, 0x0939, 0x0948, 0x0902 ].pack('U*'),
|
73
|
+
'i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd'
|
74
|
+
],
|
75
|
+
|
76
|
+
'G' => [
|
77
|
+
[ 0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E,
|
78
|
+
0x3092, 0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044,
|
79
|
+
0x306E, 0x304B ].pack('U*'),
|
80
|
+
'n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa'
|
81
|
+
],
|
82
|
+
|
83
|
+
'H' => [
|
84
|
+
[ 0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4,
|
85
|
+
0xC774, 0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C,
|
86
|
+
0xB2E4, 0xBA74, 0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744,
|
87
|
+
0xAE4C ].pack('U*'),
|
88
|
+
'989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c'
|
89
|
+
],
|
90
|
+
|
91
|
+
'I' => [
|
92
|
+
[ 0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435,
|
93
|
+
0x043E, 0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432,
|
94
|
+
0x043E, 0x0440, 0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443,
|
95
|
+
0x0441, 0x0441, 0x043A, 0x0438 ].pack('U*'),
|
96
|
+
'b1abfaaepdrnnbgefbadotcwatmq2g4l'
|
97
|
+
],
|
98
|
+
|
99
|
+
'J' => [
|
100
|
+
[ 0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F,
|
101
|
+
0x0070, 0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069,
|
102
|
+
0x006D, 0x0070, 0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074,
|
103
|
+
0x0065, 0x0068, 0x0061, 0x0062, 0x006C, 0x0061, 0x0072, 0x0065,
|
104
|
+
0x006E, 0x0045, 0x0073, 0x0070, 0x0061, 0x00F1, 0x006F,
|
105
|
+
0x006C ].pack('U*'),
|
106
|
+
'PorqunopuedensimplementehablarenEspaol-fmd56a'
|
107
|
+
],
|
108
|
+
|
109
|
+
'K' => [
|
110
|
+
[ 0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD,
|
111
|
+
0x006B, 0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3,
|
112
|
+
0x0063, 0x0068, 0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069,
|
113
|
+
0x1EBF, 0x006E, 0x0067, 0x0056, 0x0069, 0x1EC7, 0x0074 ].pack('U*'),
|
114
|
+
'TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g'
|
115
|
+
],
|
116
|
+
|
117
|
+
'L' => [
|
118
|
+
[ 0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148,
|
119
|
+
0x751F ].pack('U*'),
|
120
|
+
'3B-ww4c5e180e575a65lsy2b'
|
121
|
+
],
|
122
|
+
|
123
|
+
'M' => [
|
124
|
+
[ 0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069,
|
125
|
+
0x0074, 0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052,
|
126
|
+
0x002D, 0x004D, 0x004F, 0x004E, 0x004B, 0x0045, 0x0059,
|
127
|
+
0x0053 ].pack('U*'),
|
128
|
+
'-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n'
|
129
|
+
],
|
130
|
+
|
131
|
+
'N' => [
|
132
|
+
[ 0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E,
|
133
|
+
0x006F, 0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061,
|
134
|
+
0x0079, 0x002D, 0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834,
|
135
|
+
0x6240 ].pack('U*'),
|
136
|
+
'Hello-Another-Way--fc4qua05auwb3674vfr0b'
|
137
|
+
],
|
138
|
+
|
139
|
+
'O' => [
|
140
|
+
[ 0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B,
|
141
|
+
0x0032 ].pack('U*'),
|
142
|
+
'2-u9tlzr9756bt3uc0v'
|
143
|
+
],
|
144
|
+
|
145
|
+
'P' => [
|
146
|
+
[ 0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069,
|
147
|
+
0x3059, 0x308B, 0x0035, 0x79D2, 0x524D ].pack('U*'),
|
148
|
+
'MajiKoi5-783gue6qz075azm5e'
|
149
|
+
],
|
150
|
+
|
151
|
+
'Q' => [
|
152
|
+
[ 0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3,
|
153
|
+
0x30D0 ].pack('U*'),
|
154
|
+
'de-jg4avhby1noc0d'
|
155
|
+
],
|
156
|
+
|
157
|
+
'R' => [
|
158
|
+
[ 0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067 ].pack('U*'),
|
159
|
+
'd9juau41awczczp'
|
160
|
+
],
|
161
|
+
|
162
|
+
'S' => [
|
163
|
+
[ 0x002D, 0x003E, 0x0020, 0x0024, 0x0031, 0x002E, 0x0030, 0x0030,
|
164
|
+
0x0020, 0x003C, 0x002D ].pack('U*'),
|
165
|
+
'-> $1.00 <--'
|
166
|
+
]
|
167
|
+
}
|
168
|
+
|
169
|
+
def setup
|
170
|
+
end
|
171
|
+
|
172
|
+
def teardown
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_encode_RFC3492
|
176
|
+
TESTCASES_RFC3492.each do |key, val|
|
177
|
+
rc = Punycode.encode(val[0])
|
178
|
+
assert_equal(val[1], rc, "TestCase #{key} failed")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_decode_RFC3492
|
183
|
+
TESTCASES_RFC3492.each do |key, val|
|
184
|
+
rc = Punycode.decode(val[1])
|
185
|
+
assert_equal(val[0], rc, "TestCase #{key} failed")
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Unit tests for IDN::Stringprep.
|
2
|
+
#
|
3
|
+
# Copyright (c) 2005-2006 Erik Abele. All rights reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# Please see the file called LICENSE for further details.
|
8
|
+
#
|
9
|
+
# You may also obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# * http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# This software is OSI Certified Open Source Software.
|
20
|
+
# OSI Certified is a certification mark of the Open Source Initiative.
|
21
|
+
|
22
|
+
require 'test/unit'
|
23
|
+
require 'idn'
|
24
|
+
|
25
|
+
class Test_Stringprep < Test::Unit::TestCase
|
26
|
+
include IDN
|
27
|
+
|
28
|
+
# STRINGPREP test vectors: UTF-8 encoded strings and the corresponding
|
29
|
+
# prepared form, according to the given profile.
|
30
|
+
|
31
|
+
TESTCASES_STRINGPREP = {
|
32
|
+
'A' => [ "Nameprep", "\xC5\x83\xCD\xBA", "\xC5\x84 \xCE\xB9" ],
|
33
|
+
'B' => [ "Nodeprep", "\xE1\xBE\xB7", "\xE1\xBE\xB6\xCE\xB9" ],
|
34
|
+
'C' => [ "Resourceprep", "foo@bar", "foo@bar" ],
|
35
|
+
'D' => [ "ISCSIprep", "Example-Name", "example-name" ],
|
36
|
+
'E' => [ "SASLprep", "Example\xC2\xA0Name", "Example Name" ]
|
37
|
+
}
|
38
|
+
|
39
|
+
# STRINGPREP_INVALID test vectors: invalid input strings and their
|
40
|
+
# corresponding profile.
|
41
|
+
|
42
|
+
TESTCASES_STRINGPREP_INVALID = {
|
43
|
+
'A' => [ "Nodeprep", "toto@a/a" ]
|
44
|
+
}
|
45
|
+
|
46
|
+
# NFKC test vectors: UTF-8 encoded strings and the corresponding
|
47
|
+
# normalized form, according to NFKC normalization mode.
|
48
|
+
|
49
|
+
TESTCASES_NFKC = {
|
50
|
+
'A' => [ "\xC2\xB5", "\xCE\xBC" ],
|
51
|
+
'B' => [ "\xC2\xAA", "\x61" ]
|
52
|
+
}
|
53
|
+
|
54
|
+
def setup
|
55
|
+
end
|
56
|
+
|
57
|
+
def teardown
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_with_profile_STRINGPREP
|
61
|
+
TESTCASES_STRINGPREP.each do |key, val|
|
62
|
+
rc = Stringprep.with_profile(val[1], val[0])
|
63
|
+
assert_equal(val[2], rc, "TestCase #{key} failed")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_with_profile_STRINGPREP_INVALID
|
68
|
+
TESTCASES_STRINGPREP_INVALID.each do |key, val|
|
69
|
+
assert_raise(Stringprep::StringprepError, "TestCase #{key} failed") do
|
70
|
+
Stringprep.with_profile(val[0], val[1])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_nfkc_normalize_NFKC
|
76
|
+
TESTCASES_NFKC.each do |key, val|
|
77
|
+
rc = Stringprep.nfkc_normalize(val[0])
|
78
|
+
assert_equal(val[1], rc, "TestCase #{key} failed")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/test/ts_IDN.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Test suite for LibIDN Ruby Bindings.
|
2
|
+
#
|
3
|
+
# Copyright (c) 2005 Erik Abele. All rights reserved.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# Please see the file called LICENSE for further details.
|
8
|
+
#
|
9
|
+
# You may also obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# * http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# This software is OSI Certified Open Source Software.
|
20
|
+
# OSI Certified is a certification mark of the Open Source Initiative.
|
21
|
+
|
22
|
+
require 'test/unit'
|
23
|
+
|
24
|
+
# Construct absolute project path.
|
25
|
+
#project_path = File.join(File.dirname(__FILE__), '..')
|
26
|
+
|
27
|
+
# Add project directories to global LOAD_PATH ($:).
|
28
|
+
#$:.unshift File.join(project_path, 'ext'), File.join(project_path, 'lib')
|
29
|
+
|
30
|
+
# Require all testcase files.
|
31
|
+
#Dir[File.join(project_path, 'test', 'tc_*.rb')].each { |tc| require tc }
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: idn-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Erik Abele
|
13
|
+
- Bharanee Rathna
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-31 00:00:00 +10:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: "\n Ruby Bindings for the GNU LibIDN library, an implementation of the\n Stringprep, Punycode and IDNA specifications defined by the IETF\n Internationalized Domain Names (IDN) working group.\n\n Included are the most important parts of the Stringprep, Punycode\n and IDNA APIs like performing Stringprep processings, encoding to\n and decoding from Punycode strings and converting entire domain names\n to and from the ACE encoded form.\n "
|
23
|
+
email: deepfryed@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions:
|
27
|
+
- ext/extconf.rb
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README
|
31
|
+
files:
|
32
|
+
- CHANGES
|
33
|
+
- LICENSE
|
34
|
+
- NOTICE
|
35
|
+
- README
|
36
|
+
- Rakefile
|
37
|
+
- ext/idn.c
|
38
|
+
- ext/idn.h
|
39
|
+
- ext/idna.c
|
40
|
+
- ext/punycode.c
|
41
|
+
- ext/stringprep.c
|
42
|
+
- test/ts_IDN.rb
|
43
|
+
- test/tc_Punycode.rb
|
44
|
+
- test/tc_Stringprep.rb
|
45
|
+
- test/tc_Idna.rb
|
46
|
+
- ext/extconf.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/deepfryed/idn-ruby
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.7
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: LibIDN Ruby Bindings.
|
79
|
+
test_files:
|
80
|
+
- test/ts_IDN.rb
|
81
|
+
- test/tc_Punycode.rb
|
82
|
+
- test/tc_Stringprep.rb
|
83
|
+
- test/tc_Idna.rb
|