icu 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/icu/extconf.rb +29 -33
- data/ext/icu/icu_spoof_checker.c +75 -26
- data/ext/icu/internal_utils.c +1 -0
- data/lib/icu/version.rb +1 -1
- data/spec/spoof_checker_spec.rb +26 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d1207d28f79754afd8b68f7ecf9d298d62f4aab
|
4
|
+
data.tar.gz: ce0b6e3e1fcc8ca6bdac3091ddbda9111f3cb99b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9acb80e891bd190cfde5b4a877723d97c31c25ea30004c70f5cb8232c93ffd9c3d413d57ef08d01713068352c2163906cd79bbc2efea4f572ac558b1b09763a8
|
7
|
+
data.tar.gz: f3e384258d81c4e2435797cb58754b471535ae90bd6b7bcaee67177023ea8a20fa1e4eab21b24c687e0b910a93a41ceed902a9d43a4b59c0ceea114cd9980fad
|
data/ext/icu/extconf.rb
CHANGED
@@ -85,14 +85,14 @@ else
|
|
85
85
|
|
86
86
|
if static_p
|
87
87
|
self.configure_options += [
|
88
|
-
"--enable-shared",
|
89
88
|
"--enable-static",
|
89
|
+
"--enable-shared",
|
90
90
|
"--disable-renaming"
|
91
91
|
]
|
92
92
|
env['CFLAGS'] = "-fPIC #{env['CFLAGS']}"
|
93
93
|
env['CPPFLAGS'] = "-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=0 -DU_STATIC_IMPLEMENTATION #{env['CPPFLAGS']}"
|
94
94
|
env['CXXFLAGS'] = "-fPIC -fno-exceptions #{env['CXXFLAGS']}"
|
95
|
-
env['LDFLAGS'] = "-
|
95
|
+
env['LDFLAGS'] = "-static-libstdc++ #{env['CFLAGS']}"
|
96
96
|
else
|
97
97
|
self.configure_options += [
|
98
98
|
"--enable-shared",
|
@@ -167,7 +167,6 @@ If you are using Bundler, tell it to use the option:
|
|
167
167
|
|
168
168
|
static_p = enable_config('static', true) or
|
169
169
|
message "Static linking is disabled.\n"
|
170
|
-
recipes = []
|
171
170
|
|
172
171
|
libicu_recipe = ICURecipe.new("libicu", "59.1", static_p) do |recipe|
|
173
172
|
recipe.files = [{
|
@@ -191,9 +190,8 @@ If you are using Bundler, tell it to use the option:
|
|
191
190
|
# Primary key fingerprint: BA90 283A 60D6 7BA0 DD91 0A89 3932 080F 4FB4 19E3
|
192
191
|
}]
|
193
192
|
end
|
194
|
-
recipes.push libicu_recipe
|
195
193
|
|
196
|
-
|
194
|
+
libicu_recipe.tap do |recipe|
|
197
195
|
checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
|
198
196
|
unless File.exist?(checkpoint)
|
199
197
|
recipe.cook
|
@@ -203,40 +201,38 @@ If you are using Bundler, tell it to use the option:
|
|
203
201
|
recipe.activate
|
204
202
|
end
|
205
203
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
$LIBPATH = [$1] | $LIBPATH
|
220
|
-
else
|
221
|
-
$LIBPATH = $LIBPATH | [$1]
|
222
|
-
end
|
223
|
-
when /\A-l./
|
224
|
-
libs.unshift(arg)
|
225
|
-
else
|
226
|
-
$LDFLAGS << ' ' << arg.shellescape
|
227
|
-
end
|
204
|
+
libname = libicu_recipe.name[/\Alib(.+)\z/, 1]
|
205
|
+
# TODO: build with pkg-config
|
206
|
+
# Should do like PKG_CONFIG_PATH=/root/icu4r/ports/x86_64-pc-linux-gnu/libicu/59.1/lib/pkgconfig/ pkg-config --static icu-uc
|
207
|
+
File.join(libicu_recipe.path, "bin", "#{libname}-config").tap do |config|
|
208
|
+
# call config scripts explicit with 'sh' for compat with Windows
|
209
|
+
`sh #{config} --ldflags`.strip.shellsplit.each do |arg|
|
210
|
+
case arg
|
211
|
+
when /\A-L(.+)\z/
|
212
|
+
# Prioritize ports' directories
|
213
|
+
if $1.start_with?(ROOT + '/')
|
214
|
+
$LIBPATH.unshift($1)
|
215
|
+
else
|
216
|
+
$LIBPATH.push($1)
|
228
217
|
end
|
229
|
-
|
230
|
-
$
|
218
|
+
when /\A-l./
|
219
|
+
$LDFLAGS << ' ' << arg
|
220
|
+
else
|
221
|
+
$LDFLAGS << ' ' << arg.shellescape
|
231
222
|
end
|
232
223
|
end
|
233
|
-
|
234
|
-
|
224
|
+
$INCFLAGS = `sh #{config} --cppflags-searchpath `.strip << ' ' << $INCFLAGS
|
225
|
+
$CPPFLAGS = '-DU_DISABLE_RENAMING=1 -DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=0 -DU_STATIC_IMPLEMENTATION' << ' ' << $CPPFLAGS
|
226
|
+
$CFLAGS = `sh #{config} --cflags`.strip << $CFLAGS
|
227
|
+
end
|
235
228
|
end
|
236
229
|
|
237
230
|
$CFLAGS << ' -O3 -funroll-loops -std=c99'
|
238
231
|
$CFLAGS << ' -Wextra -O0 -ggdb3' if ENV['DEBUG']
|
239
232
|
|
240
|
-
|
241
|
-
|
233
|
+
unless have_library('icui18n', 'u_errorName') or
|
234
|
+
have_library('libicui18n', 'u_errorName') or
|
235
|
+
find_library('icui18n', 'u_errorName', *$LIBPATH)
|
236
|
+
crash("ICU build not found.")
|
237
|
+
end
|
242
238
|
create_makefile('icu/icu')
|
data/ext/icu/icu_spoof_checker.c
CHANGED
@@ -148,40 +148,89 @@ VALUE spoof_checker_get_skeleton(VALUE self, VALUE str)
|
|
148
148
|
return icu_ustring_to_rb_enc_str_with_len(out, len_bytes);
|
149
149
|
}
|
150
150
|
|
151
|
-
|
151
|
+
VALUE spoof_checker_check(VALUE self, VALUE rb_str)
|
152
|
+
{
|
153
|
+
StringValue(rb_str);
|
154
|
+
GET_SPOOF_CHECKER(this);
|
155
|
+
|
156
|
+
UErrorCode status = U_ZERO_ERROR;
|
157
|
+
int32_t result = 0;
|
158
|
+
|
159
|
+
if (icu_is_rb_str_as_utf_8(rb_str)) {
|
160
|
+
result = uspoof_check2UTF8(this->service,
|
161
|
+
RSTRING_PTR(rb_str),
|
162
|
+
RSTRING_LENINT(rb_str),
|
163
|
+
NULL,
|
164
|
+
&status);
|
165
|
+
} else {
|
166
|
+
VALUE in = icu_ustring_from_rb_str(rb_str);
|
167
|
+
result = uspoof_check2(this->service,
|
168
|
+
icu_ustring_ptr(in),
|
169
|
+
icu_ustring_len(in),
|
170
|
+
NULL,
|
171
|
+
&status);
|
172
|
+
}
|
173
|
+
if (U_FAILURE(status)) {
|
174
|
+
icu_rb_raise_icu_error(status);
|
175
|
+
}
|
176
|
+
|
177
|
+
return INT2NUM(result);
|
178
|
+
}
|
179
|
+
|
180
|
+
static const char* k_checks_name = "@checks";
|
181
|
+
|
182
|
+
VALUE spoof_checker_available_checks(VALUE klass)
|
183
|
+
{
|
184
|
+
VALUE iv = rb_iv_get(klass, k_checks_name);
|
185
|
+
if (NIL_P(iv)) {
|
186
|
+
iv = rb_hash_new();
|
187
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("single_script_confusable")), INT2NUM(USPOOF_SINGLE_SCRIPT_CONFUSABLE));
|
188
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("mixed_script_confusable")), INT2NUM(USPOOF_MIXED_SCRIPT_CONFUSABLE));
|
189
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("whole_script_confusable")), INT2NUM(USPOOF_WHOLE_SCRIPT_CONFUSABLE));
|
190
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("confusable")), INT2NUM(USPOOF_CONFUSABLE));
|
191
|
+
// USPOOF_ANY_CASE deprecated in 58
|
192
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("restriction_level")), INT2NUM(USPOOF_RESTRICTION_LEVEL));
|
193
|
+
// USPOOF_SINGLE_SCRIPT deprecated in 51
|
194
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("invisible")), INT2NUM(USPOOF_INVISIBLE));
|
195
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("char_limit")), INT2NUM(USPOOF_CHAR_LIMIT));
|
196
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("mixed_numbers")), INT2NUM(USPOOF_MIXED_NUMBERS));
|
197
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("all_checks")), INT2NUM(USPOOF_ALL_CHECKS));
|
198
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("aux_info")), INT2NUM(USPOOF_AUX_INFO));
|
199
|
+
rb_iv_set(klass, k_checks_name, iv);
|
200
|
+
}
|
201
|
+
return iv;
|
202
|
+
}
|
203
|
+
|
204
|
+
static const char* k_restriction_level_name = "@restriction_levels";
|
205
|
+
|
206
|
+
VALUE spoof_checker_available_restriction_levels(VALUE klass)
|
207
|
+
{
|
208
|
+
VALUE iv = rb_iv_get(klass, k_restriction_level_name);
|
209
|
+
if (NIL_P(iv)) {
|
210
|
+
iv = rb_hash_new();
|
211
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("ascii")), INT2NUM(USPOOF_ASCII));
|
212
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("single_script_restrictive")), INT2NUM(USPOOF_SINGLE_SCRIPT_RESTRICTIVE));
|
213
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("highly_restrictive")), INT2NUM(USPOOF_HIGHLY_RESTRICTIVE));
|
214
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("moderately_restrictive")), INT2NUM(USPOOF_MODERATELY_RESTRICTIVE));
|
215
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("minimally_restrictive")), INT2NUM(USPOOF_MINIMALLY_RESTRICTIVE));
|
216
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("unrestrictive")), INT2NUM(USPOOF_UNRESTRICTIVE));
|
217
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("restriction_level_mask")), INT2NUM(USPOOF_RESTRICTION_LEVEL_MASK));
|
218
|
+
rb_hash_aset(iv, ID2SYM(rb_intern("undefined_restrictive")), INT2NUM(USPOOF_UNDEFINED_RESTRICTIVE));
|
219
|
+
rb_iv_set(klass, k_restriction_level_name, iv);
|
220
|
+
}
|
221
|
+
return iv;
|
222
|
+
}
|
152
223
|
|
153
224
|
void init_icu_spoof_checker(void)
|
154
225
|
{
|
155
226
|
rb_cICU_SpoofChecker = rb_define_class_under(rb_mICU, "SpoofChecker", rb_cObject);
|
156
|
-
|
157
|
-
|
158
|
-
rb_include_module(rb_cICU_SpoofChecker, rb_mChecks);
|
159
|
-
rb_include_module(rb_cICU_SpoofChecker, rb_mRestrictionLevel);
|
160
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, SINGLE_SCRIPT_CONFUSABLE);
|
161
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, MIXED_SCRIPT_CONFUSABLE);
|
162
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, WHOLE_SCRIPT_CONFUSABLE);
|
163
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, CONFUSABLE);
|
164
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, ANY_CASE);
|
165
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, RESTRICTION_LEVEL);
|
166
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, SINGLE_SCRIPT);
|
167
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, INVISIBLE);
|
168
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, CHAR_LIMIT);
|
169
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, MIXED_NUMBERS);
|
170
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, ALL_CHECKS);
|
171
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mChecks, AUX_INFO);
|
172
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mRestrictionLevel, ASCII);
|
173
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mRestrictionLevel, SINGLE_SCRIPT_RESTRICTIVE);
|
174
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mRestrictionLevel, HIGHLY_RESTRICTIVE);
|
175
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mRestrictionLevel, MODERATELY_RESTRICTIVE);
|
176
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mRestrictionLevel, MINIMALLY_RESTRICTIVE);
|
177
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mRestrictionLevel, UNRESTRICTIVE);
|
178
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mRestrictionLevel, RESTRICTION_LEVEL_MASK);
|
179
|
-
DEFINE_SPOOF_ENUM_CONST(rb_mRestrictionLevel, UNDEFINED_RESTRICTIVE);
|
180
|
-
|
227
|
+
rb_define_singleton_method(rb_cICU_SpoofChecker, "available_checks", spoof_checker_available_checks, 0);
|
228
|
+
rb_define_singleton_method(rb_cICU_SpoofChecker, "available_restriction_levels", spoof_checker_available_restriction_levels, 0);
|
181
229
|
rb_define_alloc_func(rb_cICU_SpoofChecker, spoof_checker_alloc);
|
182
230
|
rb_define_method(rb_cICU_SpoofChecker, "initialize", spoof_checker_initialize, 0);
|
183
231
|
rb_define_method(rb_cICU_SpoofChecker, "restriction_level", spoof_checker_get_restriction_level, 0);
|
184
232
|
rb_define_method(rb_cICU_SpoofChecker, "restriction_level=", spoof_checker_set_restriction_level, 1);
|
233
|
+
rb_define_method(rb_cICU_SpoofChecker, "check", spoof_checker_check, 1);
|
185
234
|
rb_define_method(rb_cICU_SpoofChecker, "checks", spoof_checker_get_checks, 0);
|
186
235
|
rb_define_method(rb_cICU_SpoofChecker, "checks=", spoof_checker_set_checks, 1);
|
187
236
|
rb_define_method(rb_cICU_SpoofChecker, "confusable?", spoof_checker_confusable, 2);
|
data/ext/icu/internal_utils.c
CHANGED
data/lib/icu/version.rb
CHANGED
data/spec/spoof_checker_spec.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ICU::SpoofChecker do
|
4
|
+
let(:checker) { ICU::SpoofChecker.new }
|
4
5
|
describe 'get and set checks' do
|
5
6
|
it 'is successful' do
|
6
|
-
|
7
|
-
expect(
|
8
|
-
|
9
|
-
expect(
|
7
|
+
checker.checks = ICU::SpoofChecker.available_checks[:char_limit] | ICU::SpoofChecker.available_checks[:mixed_numbers]
|
8
|
+
expect(checker.checks).to eq ICU::SpoofChecker.available_checks[:char_limit] | ICU::SpoofChecker.available_checks[:mixed_numbers]
|
9
|
+
checker.checks = ICU::SpoofChecker.available_checks[:all_checks] & ~ICU::SpoofChecker.available_checks[:confusable]
|
10
|
+
expect(checker.checks).to eq ICU::SpoofChecker.available_checks[:all_checks] & ~ICU::SpoofChecker.available_checks[:confusable]
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
describe 'get and set restriction_level' do
|
14
15
|
it 'is successful' do
|
15
|
-
|
16
|
-
expect(
|
16
|
+
checker.restriction_level = ICU::SpoofChecker.available_restriction_levels[:highly_restrictive]
|
17
|
+
expect(checker.restriction_level).to eq ICU::SpoofChecker.available_restriction_levels[:highly_restrictive]
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
@@ -21,9 +22,9 @@ describe ICU::SpoofChecker do
|
|
21
22
|
shared_examples "confusable example" do |encodings|
|
22
23
|
encodings.each do |encoding|
|
23
24
|
it "can examine the confusable" do
|
24
|
-
expect(
|
25
|
-
expect(
|
26
|
-
expect(
|
25
|
+
expect(checker.confusable?("lscopecC鬼obƅa", "1scopecC⿁оbьа")).to be > 0
|
26
|
+
expect(checker.confusable?("lscopecC鬼obƅa".encode(encoding), "1scopecC⿁оbьа")).to be > 0
|
27
|
+
expect(checker.confusable?("lscopecC鬼obƅa".encode(encoding), "1scopecC⿁оbьа".encode(encoding))).to be > 0
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -31,9 +32,9 @@ describe ICU::SpoofChecker do
|
|
31
32
|
shared_examples "normal example" do |encodings|
|
32
33
|
encodings.each do |encoding|
|
33
34
|
it "returns 0 when it's not confusable" do
|
34
|
-
expect(
|
35
|
-
expect(
|
36
|
-
expect(
|
35
|
+
expect(checker.confusable?("abc", "def")).to eq 0
|
36
|
+
expect(checker.confusable?("abc".encode(encoding), "def")).to eq 0
|
37
|
+
expect(checker.confusable?("abc".encode(encoding), "def".encode(encoding))).to eq 0
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -42,15 +43,21 @@ describe ICU::SpoofChecker do
|
|
42
43
|
it_should_behave_like "normal example", %w(UTF-8 UTF-16 UTF-32)
|
43
44
|
end
|
44
45
|
|
46
|
+
describe '.check' do
|
47
|
+
it 'returns a integer contains about check result' do
|
48
|
+
expect(checker.check('sсcs')).to eq ICU::SpoofChecker.available_checks[:restriction_level]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
45
52
|
describe '.get_skeleton' do
|
46
53
|
it 'can gets the skeleton representation' do
|
47
|
-
expect(
|
48
|
-
expect(
|
49
|
-
expect(
|
50
|
-
expect(
|
51
|
-
expect(
|
52
|
-
expect(
|
53
|
-
expect(
|
54
|
+
expect(checker.get_skeleton("𝔭𝒶ỿ𝕡𝕒ℓ")).not_to be_empty
|
55
|
+
expect(checker.get_skeleton("𝔭𝒶ỿ𝕡𝕒ℓ") == checker.get_skeleton("ρ⍺у𝓅𝒂ן")).to be_truthy
|
56
|
+
expect(checker.get_skeleton("𝔭𝒶ỿ𝕡𝕒ℓ".encode("UTF-16")) == checker.get_skeleton("ρ⍺у𝓅𝒂ן")).to be_truthy
|
57
|
+
expect(checker.get_skeleton("𝔭𝒶ỿ𝕡𝕒ℓ".encode("UTF-16")) == checker.get_skeleton("ρ⍺у𝓅𝒂ן".encode("UTF-16"))).to be_truthy
|
58
|
+
expect(checker.get_skeleton("𝔭𝒶ỿ𝕡𝕒ℓ") == checker.get_skeleton("paypal")).to be_truthy
|
59
|
+
expect(checker.get_skeleton("𝔭𝒶ỿ𝕡𝕒ℓ") == checker.get_skeleton("ρ⍺у𝓅𝒂ן")).to be_truthy
|
60
|
+
expect(checker.get_skeleton("𝔭𝒶ỿ𝕡𝕒ℓ") == checker.get_skeleton("paypal")).to be_truthy
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erick Guan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|