domain-validator-jp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +47 -0
- data/README.md +39 -0
- data/Rakefile +5 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/domain-validator-jp.gemspec +28 -0
- data/lib/domain_validator_jp.rb +96 -0
- data/lib/domain_validator_jp/version.rb +3 -0
- metadata +125 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8c5bca455a5e823e38c62b4c8ad018fe7a98a4e59ded8ab8417642bc604d8cdb
|
|
4
|
+
data.tar.gz: 33bfed4386c6d23f7ef920e5d51534d3c8126aa3de109683104ffb615dd164ab
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 55bb68dda7215d56140b5398ab4d444865f613458d3d3557773d3d51010986c38117862af232604af571c427d237a059de63a409ee6146fffc7dfc6e7cc0830c
|
|
7
|
+
data.tar.gz: f321c98ad746f03298ce917579e72c1357693796ce588aef7b57ae82d75353f28b2e664e68ff58921fba0209ec60ff6e35dd9435bf783d4c46f517bfd242c9b8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
language: ruby
|
|
2
|
+
rvm:
|
|
3
|
+
- 2.3
|
|
4
|
+
- 2.4
|
|
5
|
+
- 2.5
|
|
6
|
+
script:
|
|
7
|
+
- bundle exec rspec
|
|
8
|
+
notifications:
|
|
9
|
+
slack:
|
|
10
|
+
secure: bvLSk8zPPWHadhXNyckezP0gzZJJHMwoC13JS5R3I2+K0NGjyinR4TNQEZDbzDKvWSvogF5zp+fY+adokUXN1TNpY3dg2uZxAEEa9+YpES2BQQsM+uQvDmUMimmrvmQB64BiNpR9u6TiAifYkSqUllLvxI210W3HZBQ7uzPzsPNitT0xsaja81fJtCiiKIuzzjngSXiA/dRfI87FT55gjx/AAB8FizeHcMx2s2yfOM4Htk5d4ocEouF5IqIjaqs/lqMky8uWdOLGGOy8eQ53A47XlUMkrmsQAUJ0RC3j0VnYxj8+SSwQtcKQepKwqlZRutpZI2mpJzeGGNO9qJCZQgnBfMsq5gJ1+H4iryAJ7UhtnkdG9f64+/3AZyvtOUrA8RgEjTWYIl97IjZJpWz+1NK0pUDbU7d/BGIwr8PzHdUF42VSWTbkFq2DuhXVZS+174fZFUayf5ayp2UBcTXBV8Big93+rWAz76ROHJzxykwZdDxxalrEMRbMm+GAf0/aPRjytBZ8klQA4ltP/K+/I8juFe7kf5E32wjKHjc8V/gzrNooCf2vfqHFp9u1+nvqokTu4+Qofeb9w2ou+l1qOtoL4wyLtHFChhVev792ab4sEuGCvhgBmSKZhYnvTPvCfP9kIlxG9gXc3myZqBvA46ad2LxeF+cbuuL2SRq86g4=
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
domain-validator-jp (0.1.0)
|
|
5
|
+
public_suffix
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
byebug (10.0.2)
|
|
11
|
+
coderay (1.1.2)
|
|
12
|
+
diff-lcs (1.3)
|
|
13
|
+
method_source (0.9.0)
|
|
14
|
+
pry (0.11.3)
|
|
15
|
+
coderay (~> 1.1.0)
|
|
16
|
+
method_source (~> 0.9.0)
|
|
17
|
+
pry-byebug (3.6.0)
|
|
18
|
+
byebug (~> 10.0)
|
|
19
|
+
pry (~> 0.10)
|
|
20
|
+
public_suffix (3.0.2)
|
|
21
|
+
rake (10.5.0)
|
|
22
|
+
rspec (3.7.0)
|
|
23
|
+
rspec-core (~> 3.7.0)
|
|
24
|
+
rspec-expectations (~> 3.7.0)
|
|
25
|
+
rspec-mocks (~> 3.7.0)
|
|
26
|
+
rspec-core (3.7.1)
|
|
27
|
+
rspec-support (~> 3.7.0)
|
|
28
|
+
rspec-expectations (3.7.0)
|
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
30
|
+
rspec-support (~> 3.7.0)
|
|
31
|
+
rspec-mocks (3.7.0)
|
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
33
|
+
rspec-support (~> 3.7.0)
|
|
34
|
+
rspec-support (3.7.1)
|
|
35
|
+
|
|
36
|
+
PLATFORMS
|
|
37
|
+
ruby
|
|
38
|
+
|
|
39
|
+
DEPENDENCIES
|
|
40
|
+
bundler (~> 1.16)
|
|
41
|
+
domain-validator-jp!
|
|
42
|
+
pry-byebug
|
|
43
|
+
rake (~> 10.0)
|
|
44
|
+
rspec
|
|
45
|
+
|
|
46
|
+
BUNDLED WITH
|
|
47
|
+
1.16.2
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# DomainValidatorJp
|
|
2
|
+
|
|
3
|
+
domain name validator includes JP domain
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'domain-validator-jp'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install domain-validator-jp
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```rb
|
|
24
|
+
DomainValidatorJp.new('example.jp').valid? # => true
|
|
25
|
+
DomainValidatorJp.new('日本語.jp').valid? # => true
|
|
26
|
+
|
|
27
|
+
DomainValidatorJp.new('①②③.jp').valid? # => false
|
|
28
|
+
DomainValidatorJp.new('example.wrongtld').valid? # => false
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Development
|
|
32
|
+
|
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
34
|
+
|
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kimromi/domain-validator-jp.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "domain_validator_jp"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "domain_validator_jp/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "domain-validator-jp"
|
|
8
|
+
spec.version = DomainValidatorJp::VERSION
|
|
9
|
+
spec.authors = ["kimromi"]
|
|
10
|
+
spec.email = ["kimromi4@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{domain name validator includes JP domain}
|
|
13
|
+
spec.description = %q{domain name validator includes JP domain}
|
|
14
|
+
spec.homepage = "https://github.com/kimromi/domain-validator-jp"
|
|
15
|
+
|
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
end
|
|
19
|
+
spec.bindir = "exe"
|
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_dependency "public_suffix"
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec"
|
|
27
|
+
spec.add_development_dependency "pry-byebug"
|
|
28
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require "domain_validator_jp/version"
|
|
2
|
+
require "public_suffix"
|
|
3
|
+
|
|
4
|
+
class DomainValidatorJp
|
|
5
|
+
attr_reader :domain
|
|
6
|
+
|
|
7
|
+
def initialize(domain)
|
|
8
|
+
@domain = domain
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def valid?
|
|
12
|
+
return false if include_subdomain?
|
|
13
|
+
return false unless valid_public_suffix?
|
|
14
|
+
return false unless valid_sld_not_dotted?
|
|
15
|
+
return false unless valid_sld_not_start_with_hyphen?
|
|
16
|
+
return false unless valid_sld_not_end_with_hyphen?
|
|
17
|
+
|
|
18
|
+
if sld_multibyte?
|
|
19
|
+
return false unless valid_length_sld_multibyte?
|
|
20
|
+
return false unless valid_jisx0208?
|
|
21
|
+
else
|
|
22
|
+
return false unless valid_sld_chars?
|
|
23
|
+
return false unless valid_length_domain?
|
|
24
|
+
return false unless valid_length_sld?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def parsed
|
|
31
|
+
@parsed ||= PublicSuffix.parse(domain)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def sld
|
|
35
|
+
parsed.sld
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def tld
|
|
39
|
+
parsed.tld
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# common
|
|
43
|
+
|
|
44
|
+
def include_subdomain?
|
|
45
|
+
!parsed.subdomain.nil?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def valid_public_suffix?
|
|
49
|
+
PublicSuffix.valid?(domain, default_rule: nil, ignore_private: true)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def valid_sld_not_dotted?
|
|
53
|
+
sld !~ /\./
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def valid_sld_not_start_with_hyphen?
|
|
57
|
+
sld !~ /^\-/
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def valid_sld_not_end_with_hyphen?
|
|
61
|
+
sld !~ /\-$/
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# only multibyte
|
|
65
|
+
|
|
66
|
+
def sld_multibyte?
|
|
67
|
+
sld !~ /^[0-9A-Za-z\-]+$/
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def valid_length_sld_multibyte?
|
|
71
|
+
1 <= sld.length && sld.length <= 15
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# only multibyte
|
|
75
|
+
|
|
76
|
+
def valid_sld_chars?
|
|
77
|
+
sld =~ /^[0-9A-Za-z\-]+$/
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def valid_length_domain?
|
|
81
|
+
domain.length <= 253
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def valid_length_sld?
|
|
85
|
+
sld.length <= 63
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def valid_jisx0208?
|
|
89
|
+
valid = /^#{utf8_to_sjis("[\-0-9A-Za-zぁ-んァ-ヶ亜-腕弌-熙]")}+$/
|
|
90
|
+
valid.match(utf8_to_sjis(sld)) if utf8_to_sjis(sld)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def utf8_to_sjis(str)
|
|
94
|
+
str.encode('Windows-31J') rescue nil
|
|
95
|
+
end
|
|
96
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: domain-validator-jp
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- kimromi
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-06-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: public_suffix
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.16'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.16'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: pry-byebug
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: domain name validator includes JP domain
|
|
84
|
+
email:
|
|
85
|
+
- kimromi4@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".gitignore"
|
|
91
|
+
- ".rspec"
|
|
92
|
+
- ".travis.yml"
|
|
93
|
+
- Gemfile
|
|
94
|
+
- Gemfile.lock
|
|
95
|
+
- README.md
|
|
96
|
+
- Rakefile
|
|
97
|
+
- bin/console
|
|
98
|
+
- bin/setup
|
|
99
|
+
- domain-validator-jp.gemspec
|
|
100
|
+
- lib/domain_validator_jp.rb
|
|
101
|
+
- lib/domain_validator_jp/version.rb
|
|
102
|
+
homepage: https://github.com/kimromi/domain-validator-jp
|
|
103
|
+
licenses: []
|
|
104
|
+
metadata: {}
|
|
105
|
+
post_install_message:
|
|
106
|
+
rdoc_options: []
|
|
107
|
+
require_paths:
|
|
108
|
+
- lib
|
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
|
+
requirements:
|
|
116
|
+
- - ">="
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: '0'
|
|
119
|
+
requirements: []
|
|
120
|
+
rubyforge_project:
|
|
121
|
+
rubygems_version: 2.7.3
|
|
122
|
+
signing_key:
|
|
123
|
+
specification_version: 4
|
|
124
|
+
summary: domain name validator includes JP domain
|
|
125
|
+
test_files: []
|