json_schemer 0.1.6 → 0.1.7

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: 8dc3f244ec43815a4207b9be2112cc76afee3cd37b96a3e1eb0fd9b189f8ad72
4
- data.tar.gz: 3dcede7d0418d30e98fe75054000657bf03201a1fbf8231810506a2a91de1bbb
3
+ metadata.gz: 382a4fe7c0bfaba4ac319cc29289337490b69440217d6725034e516efe5a9f97
4
+ data.tar.gz: 59abe27c6052f6f7a210a0c1a51c08ffbb231f6dfe0f5f10d1021a9ccb05b0ac
5
5
  SHA512:
6
- metadata.gz: 1ea22d403dd91c7c555d7fe949a25840255a1ed55af658aad703b965b79e063fe2ae5a1d82b3b3ac7a6a56cc32b5720ec0639d734235e934ccaef04f87a11146
7
- data.tar.gz: 243e04ef109d923d9de753856943f2269548485de36f476e9d527be132c1f737abcd1ee6e74c6b3263bb95d9b03fcfc0a6f8a11c4249d538baab0d469c97652d
6
+ metadata.gz: 59328690e27ae9ef6fe1a2c82bca000d99ea1678a39de8f81e01e5f58ffa6cb1254adfb2163ba738b784bff3067c51d429ae6eb61da83da755ca72982b704669
7
+ data.tar.gz: 003be8eb68f6f57a70aeaa1014a0e2f26f63252eddb7599b44270c15850d5195acc7a60042927714cfb2e406d0a4af6d5d5c2c4a66c905460b20fb2323e1b82c
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_schemer (0.1.6)
4
+ json_schemer (0.1.7)
5
5
  ecma-re-validator (~> 0.1.2)
6
6
  hana (~> 1.3.3)
7
+ regexp_parser (~> 0.5.0)
7
8
  uri_template (~> 0.7.0)
8
9
 
9
10
  GEM
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency "ecma-re-validator", "~> 0.1.2"
35
35
  spec.add_runtime_dependency "hana", "~> 1.3.3"
36
36
  spec.add_runtime_dependency "uri_template", "~> 0.7.0"
37
+ spec.add_runtime_dependency "regexp_parser", "~> 0.5.0"
37
38
  end
@@ -29,6 +29,13 @@ module JSONSchemer
29
29
  NET_HTTP_REF_RESOLVER = proc { |uri| JSON.parse(Net::HTTP.get(uri)) }.freeze
30
30
  BOOLEANS = Set[true, false].freeze
31
31
 
32
+ RUBY_REGEX_ANCHORS_TO_ECMA_262 = {
33
+ :bos => 'A',
34
+ :eos => 'z',
35
+ :bol => '\A',
36
+ :eol => '\z'
37
+ }.freeze
38
+
32
39
  def initialize(
33
40
  schema,
34
41
  format: true,
@@ -332,7 +339,7 @@ module JSONSchemer
332
339
 
333
340
  yield error(instance, 'maxLength') if max_length && data.size > max_length
334
341
  yield error(instance, 'minLength') if min_length && data.size < min_length
335
- yield error(instance, 'pattern') if pattern && Regexp.new(pattern) !~ data
342
+ yield error(instance, 'pattern') if pattern && ecma_262_regex(pattern) !~ data
336
343
  yield error(instance, 'format') if format? && spec_format?(format) && !valid_spec_format?(data, format)
337
344
 
338
345
  if content_encoding || content_media_type
@@ -474,7 +481,7 @@ module JSONSchemer
474
481
 
475
482
  if pattern_properties
476
483
  regex_pattern_properties ||= pattern_properties.map do |pattern, property_schema|
477
- [pattern, Regexp.new(pattern), property_schema]
484
+ [pattern, ecma_262_regex(pattern), property_schema]
478
485
  end
479
486
  regex_pattern_properties.each do |pattern, regex, property_schema|
480
487
  if regex =~ key
@@ -513,6 +520,15 @@ module JSONSchemer
513
520
  end
514
521
  end
515
522
 
523
+ def ecma_262_regex(pattern)
524
+ @ecma_262_regex ||= {}
525
+ @ecma_262_regex[pattern] ||= Regexp.new(
526
+ Regexp::Scanner.scan(pattern).map do |type, token, text|
527
+ type == :anchor ? RUBY_REGEX_ANCHORS_TO_ECMA_262.fetch(token, text) : text
528
+ end.join
529
+ )
530
+ end
531
+
516
532
  def join_uri(a, b)
517
533
  if a && b
518
534
  URI.join(a, b)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONSchemer
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  end
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: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Harsha
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-27 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.7.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: regexp_parser
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.5.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.5.0
97
111
  description:
98
112
  email:
99
113
  - davishmcclurg@gmail.com