reredos 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8adfc52f2ddfb55c386adf71cfbc23e4e1401c5674b8dff8b157bd64fa30ce21
4
- data.tar.gz: 2737d510279f2251ca065f82ba3e7caba691e8df37d08c405321197f11cbc78c
3
+ metadata.gz: 3547add122783213f2b2d21781effdcdbccf443b46faefcbbc8040896b3604e9
4
+ data.tar.gz: 92f229dfe56e23bd74a0b722f8cd200f5e8631abf37821d749cc56a55f7c97e9
5
5
  SHA512:
6
- metadata.gz: 5a6dbf7e9c48264672e305fddf747de7c50ec793cb383880ce51f8a1b06a0be57538a3845a7cf35790d8c93a1b75680ea644723ed07e5de7c59e7d22ecf1e88d
7
- data.tar.gz: 4750b12690c7094542bf0a471eb94972aa6973144c9626e0b247bad8cd8471d2c8952a0283ac49eb391fad2e3873b6741c8410206ead0f1238ca472c8dac1e30
6
+ metadata.gz: 899fe67f6ea0adfcc74e257313f09f383accff312b8c701fded469fa8bd81f28d0a95ac1bc42626580666f7234a1edfc2e58c213237e47a8dcf93071152e2d91
7
+ data.tar.gz: fc9c2e4c6a6ea49b129cb85c52c3f595b197554c0b4b1282441333997d9fb8a76978e2f6d6112c7457bf231b1929bbf3c37ac2912665b9b0cac4930f7e6a344b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reredos (0.1.1)
4
+ reredos (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,4 +32,4 @@ DEPENDENCIES
32
32
  rspec (~> 3.0)
33
33
 
34
34
  BUNDLED WITH
35
- 2.0.1
35
+ 2.0.2
data/README.md CHANGED
@@ -48,6 +48,9 @@ The gem is available as open source under the terms of the [MIT License](https:/
48
48
  Everyone interacting in the Reredos project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/reredos/blob/master/CODE_OF_CONDUCT.md).
49
49
 
50
50
  ## Release Notes
51
+ ### 0.1.2 - July 29, 2019
52
+ * Fixed a bug, that it accepted dots as first or last character of username
53
+
51
54
  ### 0.1.1 - April 26, 2019
52
55
  * Fixed a bug, that it accepted strings including new line
53
56
 
@@ -1,3 +1,3 @@
1
1
  module Reredos
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/reredos.rb CHANGED
@@ -20,18 +20,42 @@ module Reredos
20
20
 
21
21
  def valid_domain?(str)
22
22
  return false if str.length > DOMAIN_MAX_LENGTH
23
- return false if str[-1] == '-' # 末尾は-でない
24
-
25
- labels = str.split('.')
26
- return false if labels.map(&:length).any?{ |_| _ > DOMAIN_LABEL_MAX_LENGTH }
27
- return false unless labels.map{ |_| /\A[0-9a-zA-Z\-]+\z/ === _ }.all? # ラベルに含まれる文字が1文字以上の英数字orハイフン
23
+ return false unless str.split('.').all? { |l| valid_label?(l) }
28
24
 
29
25
  true
30
26
  end
31
27
 
32
28
  def valid_username?(str)
33
29
  return false if str.length > USERNAME_MAX_LENGTH
30
+ return false if str[0] == '.' || str[-1] == '.'
34
31
  /\A[0-9a-zA-Z\.\+\-\_]+\z/ === str # 既定の文字のみで構成されている
35
32
  end
33
+
34
+ # ラベルはアルファベットで始まり、アルファベットか数字かハイフンが続き、アルファベットか数字で終わる
35
+ def valid_label?(str)
36
+ return false if str.empty?
37
+ return false if str.length > DOMAIN_LABEL_MAX_LENGTH
38
+ return false unless letter?(str[0])
39
+ return false unless alphanumeric?(str[-1])
40
+ return true if str[1...-1].empty?
41
+
42
+ str[1...-1].chars.all? { |c| hyphen_or_alphanumeric?(c) }
43
+ end
44
+
45
+ def letter?(char)
46
+ ('a'..'z').include?(char) || ('A'..'Z').include?(char)
47
+ end
48
+
49
+ def digit?(char)
50
+ ('0'..'9').include?(char)
51
+ end
52
+
53
+ def alphanumeric?(char)
54
+ letter?(char) || digit?(char)
55
+ end
56
+
57
+ def hyphen_or_alphanumeric?(char)
58
+ char == '-' || alphanumeric?(char)
59
+ end
36
60
  end
37
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reredos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - expajp
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-26 00:00:00.000000000 Z
11
+ date: 2019-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler