domain_validator_jp 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/lib/domain_validator_jp.rb +67 -79
- data/lib/domain_validator_jp/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b994793dd271e71492fba726ebb405ef583f8b951f58806659b5528dcfdbd6b2
|
4
|
+
data.tar.gz: 2c657d7f2d250be49b418b6f1790292180670db5e15bdf0f6f2c922acd079b9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c03e1fd78be99e56a69e5a5df3e9a2b816807950637585dfc185736ed32d3d8c087029ad3d6a1f117afcf0831690ca22ef8dfbce1fa22e1524babe8a4c12a0a
|
7
|
+
data.tar.gz: 82e6f0df0cc35140adcbc278397dd00f28e2bd18dfc0df232665823e6b4e7bf5a9702e55cec6436fb8637690bac84d5578df5aa84f65e6f81c709f46d3cfcaf8
|
data/README.md
CHANGED
@@ -9,11 +9,10 @@ domain name validator includes JP domain
|
|
9
9
|
## Usage
|
10
10
|
|
11
11
|
```rb
|
12
|
-
DomainValidatorJp.
|
13
|
-
DomainValidatorJp.
|
14
|
-
|
15
|
-
DomainValidatorJp.
|
16
|
-
DomainValidatorJp.new('example.wrongtld').valid? # => false
|
12
|
+
DomainValidatorJp.valid?('example.jp') # => true
|
13
|
+
DomainValidatorJp.valid?('日本語.jp') # => true
|
14
|
+
DomainValidatorJp.valid?('①②③.jp') # => false
|
15
|
+
DomainValidatorJp.valid?('example.wrongtld') # => false
|
17
16
|
```
|
18
17
|
|
19
18
|
## Installation
|
data/lib/domain_validator_jp.rb
CHANGED
@@ -1,102 +1,90 @@
|
|
1
1
|
require "domain_validator_jp/version"
|
2
2
|
require "public_suffix"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
return false unless valid_length_domain?
|
25
|
-
return false unless valid_length_sld?
|
4
|
+
module DomainValidatorJp
|
5
|
+
class << self
|
6
|
+
def valid?(domain)
|
7
|
+
return false unless fqdn?(domain)
|
8
|
+
return false if include_subdomain?(domain)
|
9
|
+
return false unless valid_public_suffix?(domain)
|
10
|
+
return false unless valid_sld_not_dotted?(domain)
|
11
|
+
return false unless valid_sld_not_start_with_hyphen?(domain)
|
12
|
+
return false unless valid_sld_not_end_with_hyphen?(domain)
|
13
|
+
|
14
|
+
if sld_multibyte?(domain)
|
15
|
+
return false unless valid_length_sld_multibyte?(domain)
|
16
|
+
return false unless valid_jisx0208?(domain)
|
17
|
+
else
|
18
|
+
return false unless valid_sld_chars?(domain)
|
19
|
+
return false unless valid_length_domain?(domain)
|
20
|
+
return false unless valid_length_sld?(domain)
|
21
|
+
end
|
22
|
+
|
23
|
+
true
|
26
24
|
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
splitted = domain.split('.')
|
33
|
-
splitted.length >= 2 && splitted.all?{|label| !label.empty? }
|
34
|
-
end
|
35
|
-
|
36
|
-
def parsed
|
37
|
-
@parsed ||= PublicSuffix.parse(domain)
|
38
|
-
end
|
39
|
-
|
40
|
-
def sld
|
41
|
-
parsed.sld
|
42
|
-
end
|
26
|
+
def fqdn?(domain)
|
27
|
+
splitted = domain.split('.')
|
28
|
+
splitted.length >= 2 && splitted.all?{|label| !label.empty? }
|
29
|
+
end
|
43
30
|
|
44
|
-
|
45
|
-
|
46
|
-
|
31
|
+
def parsed(domain)
|
32
|
+
PublicSuffix.parse(domain)
|
33
|
+
end
|
47
34
|
|
48
|
-
|
35
|
+
# common
|
49
36
|
|
50
|
-
|
51
|
-
|
52
|
-
|
37
|
+
def include_subdomain?(domain)
|
38
|
+
!parsed(domain).subdomain.nil?
|
39
|
+
end
|
53
40
|
|
54
|
-
|
55
|
-
|
56
|
-
|
41
|
+
def valid_public_suffix?(domain)
|
42
|
+
PublicSuffix.valid?(domain, default_rule: nil, ignore_private: true)
|
43
|
+
end
|
57
44
|
|
58
|
-
|
59
|
-
|
60
|
-
|
45
|
+
def valid_sld_not_dotted?(domain)
|
46
|
+
parsed(domain).sld !~ /\./
|
47
|
+
end
|
61
48
|
|
62
|
-
|
63
|
-
|
64
|
-
|
49
|
+
def valid_sld_not_start_with_hyphen?(domain)
|
50
|
+
parsed(domain).sld !~ /^\-/
|
51
|
+
end
|
65
52
|
|
66
|
-
|
67
|
-
|
68
|
-
|
53
|
+
def valid_sld_not_end_with_hyphen?(domain)
|
54
|
+
parsed(domain).sld !~ /\-$/
|
55
|
+
end
|
69
56
|
|
70
|
-
|
57
|
+
# only multibyte
|
71
58
|
|
72
|
-
|
73
|
-
|
74
|
-
|
59
|
+
def sld_multibyte?(domain)
|
60
|
+
parsed(domain).sld !~ /^[0-9A-Za-z\-]+$/
|
61
|
+
end
|
75
62
|
|
76
|
-
|
77
|
-
|
78
|
-
|
63
|
+
def valid_length_sld_multibyte?(domain)
|
64
|
+
1 <= parsed(domain).sld.length && parsed(domain).sld.length <= 15
|
65
|
+
end
|
79
66
|
|
80
|
-
|
67
|
+
# only multibyte
|
81
68
|
|
82
|
-
|
83
|
-
|
84
|
-
|
69
|
+
def valid_sld_chars?(domain)
|
70
|
+
parsed(domain).sld =~ /^[0-9A-Za-z\-]+$/
|
71
|
+
end
|
85
72
|
|
86
|
-
|
87
|
-
|
88
|
-
|
73
|
+
def valid_length_domain?(domain)
|
74
|
+
domain.length <= 253
|
75
|
+
end
|
89
76
|
|
90
|
-
|
91
|
-
|
92
|
-
|
77
|
+
def valid_length_sld?(domain)
|
78
|
+
parsed(domain).sld.length <= 63
|
79
|
+
end
|
93
80
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
81
|
+
def valid_jisx0208?(domain)
|
82
|
+
valid = /^#{utf8_to_sjis("[\-0-9A-Za-zぁ-んァ-ヶ亜-腕弌-熙]")}+$/
|
83
|
+
valid.match(utf8_to_sjis(parsed(domain).sld)) if utf8_to_sjis(parsed(domain).sld)
|
84
|
+
end
|
98
85
|
|
99
|
-
|
100
|
-
|
86
|
+
def utf8_to_sjis(str)
|
87
|
+
str.encode('Windows-31J') rescue nil
|
88
|
+
end
|
101
89
|
end
|
102
90
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
module DomainValidatorJp
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
end
|