domain_validator_jp 0.1.4
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 +11 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +5 -0
- data/LICENSE +20 -0
- data/README.md +43 -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 +102 -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: 703d0df0dce33e429dbf606d1ca23e6053e5251331260fe6fe0d392a7d96b299
|
4
|
+
data.tar.gz: aa08dd03b420dea21484b5afebec87584a902534873c42df7d0f56bf45ca979f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de4938c681c48a99ae0224b53865d0bf2faff7fdf796033dd446e223f0a6cd3c783d9fea37db3926b343c2c52780c96679c3eb38793e6397f1651c0aad64153a
|
7
|
+
data.tar.gz: e219d06afef340342b61002e1c810b01ae44a4e19117e6a7e9e4dd8fa0ecdb15566b1e593934020ce457443da5bf57401f92caadd8dfb0875b0b7c29a6be63f8
|
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: UkhsxJEnkywqW1n8GljDZ4WCYjH/EA93E3wPRbZW9Wu9+muoCjqWaroXE62pImcYvDBk5jOKBZ2nA3xM3/R+vJl/d8XotTPz9G9fZrhcKGrZKGh0ocKRc5T0hG/ouzx2+UVWEXr+F++fKwDYjS7E/CFKAyTTv0rLn0H3nDpuGFJw3jv7ISOc2V0ctUzBpHs+HzdRBs3zOB4zA5BL9GUPYlzQyAlcQFLrTXZecYxcIm0XR41kraL3vDeOP4DITg++lsIO09coaMvQIvq7uzOiD2aiA6OKnZJIgHW1FebMCu7eV72HsUMiQLdve+zVEvoSItk6qFy81cCBoUXWJ2DUuHwrYP7buaDbQ7vWL3xzY4pJEtVycy2GHmfymKEWWXBlRdomt9QLw1EbPCuhS4tI01VbJ2NPWHpBsQym2pZ36kTaA7SI8rysi5L2+oSRcoIlmINj2RteR4Y07n5x5WgkKIws+QMRorInfN7KwmUVkwiQV+HCUUTJxw9IF+o/gLGwb0QL+aZloUCgk1cXM1aMriYYqeZdfzXSiA6ttfRKylKxibVeYNDyXHi1lwf6FRXK8evrfYJwVbVZ4wZDLUyjc1rCT2NpvTXiQMGitMjX9WUoCqspmLcstwmVNlhVfFFPhPSLYXQ3CPCXGcuWFtSxmdON64fAPtNZ8Ww0Tf/ckK0=
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 kimromi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# :jp: DomainValidatorJp
|
2
|
+
|
3
|
+
<a href="https://rubygems.org/gems/domain_validator_jp" title="npm"><img src="https://img.shields.io/gem/v/domain_validator_jp.svg"></a>
|
4
|
+
<a href="https://travis-ci.org/kimromi/domain_validator_jp" title="travis"><img src="https://img.shields.io/travis/kimromi/domain_validator_jp.svg"></a>
|
5
|
+
<a href="https://github.com/kimromi/domain_validator_jp/blob/master/LICENSE" title="MIT License"><img src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
6
|
+
|
7
|
+
domain name validator includes JP domain
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```rb
|
12
|
+
DomainValidatorJp.new('example.jp').valid? # => true
|
13
|
+
DomainValidatorJp.new('日本語.jp').valid? # => true
|
14
|
+
|
15
|
+
DomainValidatorJp.new('①②③.jp').valid? # => false
|
16
|
+
DomainValidatorJp.new('example.wrongtld').valid? # => false
|
17
|
+
```
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'domain_validator_jp'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install domain_validator_jp
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
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.
|
38
|
+
|
39
|
+
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).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
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,102 @@
|
|
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 unless fqdn?
|
13
|
+
return false if include_subdomain?
|
14
|
+
return false unless valid_public_suffix?
|
15
|
+
return false unless valid_sld_not_dotted?
|
16
|
+
return false unless valid_sld_not_start_with_hyphen?
|
17
|
+
return false unless valid_sld_not_end_with_hyphen?
|
18
|
+
|
19
|
+
if sld_multibyte?
|
20
|
+
return false unless valid_length_sld_multibyte?
|
21
|
+
return false unless valid_jisx0208?
|
22
|
+
else
|
23
|
+
return false unless valid_sld_chars?
|
24
|
+
return false unless valid_length_domain?
|
25
|
+
return false unless valid_length_sld?
|
26
|
+
end
|
27
|
+
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def fqdn?
|
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
|
43
|
+
|
44
|
+
def tld
|
45
|
+
parsed.tld
|
46
|
+
end
|
47
|
+
|
48
|
+
# common
|
49
|
+
|
50
|
+
def include_subdomain?
|
51
|
+
!parsed.subdomain.nil?
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid_public_suffix?
|
55
|
+
PublicSuffix.valid?(domain, default_rule: nil, ignore_private: true)
|
56
|
+
end
|
57
|
+
|
58
|
+
def valid_sld_not_dotted?
|
59
|
+
sld !~ /\./
|
60
|
+
end
|
61
|
+
|
62
|
+
def valid_sld_not_start_with_hyphen?
|
63
|
+
sld !~ /^\-/
|
64
|
+
end
|
65
|
+
|
66
|
+
def valid_sld_not_end_with_hyphen?
|
67
|
+
sld !~ /\-$/
|
68
|
+
end
|
69
|
+
|
70
|
+
# only multibyte
|
71
|
+
|
72
|
+
def sld_multibyte?
|
73
|
+
sld !~ /^[0-9A-Za-z\-]+$/
|
74
|
+
end
|
75
|
+
|
76
|
+
def valid_length_sld_multibyte?
|
77
|
+
1 <= sld.length && sld.length <= 15
|
78
|
+
end
|
79
|
+
|
80
|
+
# only multibyte
|
81
|
+
|
82
|
+
def valid_sld_chars?
|
83
|
+
sld =~ /^[0-9A-Za-z\-]+$/
|
84
|
+
end
|
85
|
+
|
86
|
+
def valid_length_domain?
|
87
|
+
domain.length <= 253
|
88
|
+
end
|
89
|
+
|
90
|
+
def valid_length_sld?
|
91
|
+
sld.length <= 63
|
92
|
+
end
|
93
|
+
|
94
|
+
def valid_jisx0208?
|
95
|
+
valid = /^#{utf8_to_sjis("[\-0-9A-Za-zぁ-んァ-ヶ亜-腕弌-熙]")}+$/
|
96
|
+
valid.match(utf8_to_sjis(sld)) if utf8_to_sjis(sld)
|
97
|
+
end
|
98
|
+
|
99
|
+
def utf8_to_sjis(str)
|
100
|
+
str.encode('Windows-31J') rescue nil
|
101
|
+
end
|
102
|
+
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.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kimromi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-19 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
|
+
- LICENSE
|
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: []
|