json_schemer 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57b910832ad52857f782a9e0c9d17247b3d298493e2876d4d87dcc7bd72c623e
4
- data.tar.gz: 4f36b7e698c0de3b9cac3d5fc54572dfd2288f28e0e29c7475f162cf5e878c95
3
+ metadata.gz: '03538ce8b7525466940396aecbfffeac23f2f942af4e11023ea370d73045ec8b'
4
+ data.tar.gz: a06e7a91e8c851dffac5b9ecab91e47b6e89d46173abc8f95619dc4eca7f938d
5
5
  SHA512:
6
- metadata.gz: 6cb5d43a92de555b7fb72febcd305990b94ed7764bfb300a158ec3ee864e4d7c9944afa4ff4726ce30e57af0325a8bb9e295e281b4b981cc459f44ddd3e507da
7
- data.tar.gz: f41eab50d37542486c230fcbe14a57c7dbb6564acac9815a3ff4b9977a7683a9703162d59650e34c3dc640693fa919c6b607403e575b233c77468fcc39f0703b
6
+ metadata.gz: 87f3d572f430bc5b64f25ffc96bf5fcf979fa53eea9e0d325e6d0b853b4f653d2264e151ab312da4e472a02342eb162e9ffdfa3b06c3ec29fa09e39123412f3a
7
+ data.tar.gz: fbbed8f04fea519b2264075051e64a7f6af2ade9b92600a490a2291065ed9a13eb15fb73cf356a0caff5ea3f63065d4c7a50ff93b293441273ed98708429cfe8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_schemer (1.0.2)
4
+ json_schemer (1.0.3)
5
5
  hana (~> 1.3)
6
6
  regexp_parser (~> 2.0)
7
7
  simpleidn (~> 0.2)
@@ -13,7 +13,7 @@ GEM
13
13
  hana (1.3.7)
14
14
  minitest (5.15.0)
15
15
  rake (13.0.6)
16
- regexp_parser (2.6.1)
16
+ regexp_parser (2.8.1)
17
17
  simplecov (0.22.0)
18
18
  docile (~> 1.1)
19
19
  simplecov-html (~> 0.11)
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+ module JSONSchemer
3
+ module Format
4
+ module Email
5
+ # https://datatracker.ietf.org/doc/html/rfc6531#section-3.3
6
+ # I think this is the same as "UTF8-non-ascii"? (https://datatracker.ietf.org/doc/html/rfc6532#section-3.1)
7
+ UTF8_NON_ASCII = '[^[:ascii:]]'
8
+ # https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.2
9
+ A_TEXT = "([\\w!#$%&'*+\\-/=?\\^`{|}~]|#{UTF8_NON_ASCII})" # atext = ALPHA / DIGIT / ; Printable US-ASCII
10
+ # "!" / "#" / ; characters not including
11
+ # "$" / "%" / ; specials. Used for atoms.
12
+ # "&" / "'" /
13
+ # "*" / "+" /
14
+ # "-" / "/" /
15
+ # "=" / "?" /
16
+ # "^" / "_" /
17
+ # "`" / "{" /
18
+ # "|" / "}" /
19
+ # "~"
20
+ Q_TEXT_SMTP = "([\\x20-\\x21\\x23-\\x5B\\x5D-\\x7E]|#{UTF8_NON_ASCII})" # qtextSMTP = %d32-33 / %d35-91 / %d93-126
21
+ # ; i.e., within a quoted string, any
22
+ # ; ASCII graphic or space is permitted
23
+ # ; without blackslash-quoting except
24
+ # ; double-quote and the backslash itself.
25
+ QUOTED_PAIR_SMTP = '\x5C[\x20-\x7E]' # quoted-pairSMTP = %d92 %d32-126
26
+ # ; i.e., backslash followed by any ASCII
27
+ # ; graphic (including itself) or SPace
28
+ Q_CONTENT_SMTP = "#{Q_TEXT_SMTP}|#{QUOTED_PAIR_SMTP}" # QcontentSMTP = qtextSMTP / quoted-pairSMTP
29
+ QUOTED_STRING = "\"(#{Q_CONTENT_SMTP})*\"" # Quoted-string = DQUOTE *QcontentSMTP DQUOTE
30
+ ATOM = "#{A_TEXT}+" # Atom = 1*atext
31
+ DOT_STRING = "#{ATOM}(\\.#{ATOM})*" # Dot-string = Atom *("." Atom)
32
+ LOCAL_PART = "#{DOT_STRING}|#{QUOTED_STRING}" # Local-part = Dot-string / Quoted-string
33
+ # ; MAY be case-sensitive
34
+ # IPv4-address-literal = Snum 3("." Snum)
35
+ # using `valid_id?` to check ip addresses because it's complicated. # IPv6-address-literal = "IPv6:" IPv6-addr
36
+ ADDRESS_LITERAL = '\[(IPv6:(?<ipv6>[\h:]+)|(?<ipv4>[\d.]+))\]' # address-literal = "[" ( IPv4-address-literal /
37
+ # IPv6-address-literal /
38
+ # General-address-literal ) "]"
39
+ # ; See Section 4.1.3
40
+ # using `valid_hostname?` to check domain because it's complicated
41
+ MAILBOX = "(#{LOCAL_PART})@(#{ADDRESS_LITERAL}|(?<domain>.+))" # Mailbox = Local-part "@" ( Domain / address-literal )
42
+ EMAIL_REGEX = /\A#{MAILBOX}\z/
43
+
44
+ def valid_email?(data)
45
+ return false unless match = EMAIL_REGEX.match(data)
46
+ if ipv4 = match.named_captures.fetch('ipv4')
47
+ valid_ip?(ipv4, Socket::AF_INET)
48
+ elsif ipv6 = match.named_captures.fetch('ipv6')
49
+ valid_ip?(ipv6, Socket::AF_INET6)
50
+ else
51
+ valid_hostname?(match.named_captures.fetch('domain'))
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
  module JSONSchemer
3
3
  module Format
4
+ include Email
4
5
  include Hostname
5
6
  include URITemplate
6
7
 
7
- # this is no good
8
- EMAIL_REGEX = /\A[^@\s]+@([\p{L}\d-]+\.)+[\p{L}\d\-]{2,}\z/i.freeze
9
8
  JSON_POINTER_REGEX_STRING = '(\/([^~\/]|~[01])*)*'
10
9
  JSON_POINTER_REGEX = /\A#{JSON_POINTER_REGEX_STRING}\z/.freeze
11
10
  RELATIVE_JSON_POINTER_REGEX = /\A(0|[1-9]\d*)(#|#{JSON_POINTER_REGEX_STRING})?\z/.freeze
@@ -72,12 +71,6 @@ module JSONSchemer
72
71
  false
73
72
  end
74
73
 
75
- def valid_email?(data)
76
- return false unless EMAIL_REGEX.match?(data)
77
- local, _domain = data.partition('@')
78
- !local.start_with?('.') && !local.end_with?('.') && !local.include?('..')
79
- end
80
-
81
74
  def valid_ip?(data, family)
82
75
  IPAddr.new(data, family)
83
76
  IP_REGEX.match?(data)
@@ -324,7 +324,7 @@ module JSONSchemer
324
324
  ref_uri.fragment = nil
325
325
  end
326
326
 
327
- ref_object = if ids.key?(ref_uri) || ref_uri.to_s == @base_uri.to_s
327
+ ref_object = if ids.key?(ref_uri) || ref_uri.to_s.empty? || ref_uri.to_s == @base_uri.to_s
328
328
  self
329
329
  else
330
330
  child(resolve_ref(ref_uri), base_uri: ref_uri)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module JSONSchemer
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  end
data/lib/json_schemer.rb CHANGED
@@ -16,6 +16,7 @@ require 'simpleidn'
16
16
  require 'json_schemer/version'
17
17
  require 'json_schemer/format/hostname'
18
18
  require 'json_schemer/format/uri_template'
19
+ require 'json_schemer/format/email'
19
20
  require 'json_schemer/format'
20
21
  require 'json_schemer/errors'
21
22
  require 'json_schemer/cached_resolver'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schemer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Harsha
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-07 00:00:00.000000000 Z
11
+ date: 2023-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,6 +135,7 @@ files:
135
135
  - lib/json_schemer/ecma_regexp.rb
136
136
  - lib/json_schemer/errors.rb
137
137
  - lib/json_schemer/format.rb
138
+ - lib/json_schemer/format/email.rb
138
139
  - lib/json_schemer/format/hostname.rb
139
140
  - lib/json_schemer/format/uri_template.rb
140
141
  - lib/json_schemer/schema/base.rb