json_schemer 0.2.22 → 0.2.24

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: bc9ff5876e71054ee601dc4464c99560e86557796ef792e36512e1f08725a065
4
- data.tar.gz: 5ee26787348f3aecb1a591c38c7bccc7aaf4166fd14d1299999d426ecaa15893
3
+ metadata.gz: 24ab3d7f62a2ca93d0dcd3fb33191de983006b504d7bdae60066268fabf7eb50
4
+ data.tar.gz: 5f695dffd93a834e81491d5a5b328e6b193d56886666533e6ec0c5e7ba5b5be0
5
5
  SHA512:
6
- metadata.gz: 9b5dc77e4a136d9dd7ab774e530880188c3125647535707d67b9b09e615e538bfe826249fd53644d3dc452e8387667bc74a3e24ec21f847145bc4b92de15371d
7
- data.tar.gz: 160ead197e1f0a61090e936a526e4753156b185e4049db6d5ca7efb9c8bbf4430ebd9a0eff952299fc5bdb0b93a063745d9be3e919bee80ce93c05864a9655b7
6
+ metadata.gz: 0bd588c8b88bd813c52a13bb997cdd3f668f9b36570bc15a0780aa35b80fdaa49cc2862f6749be1cea9c5708169cbee990385799907a3957c7ceac32ce9ff5cf
7
+ data.tar.gz: 6c835337e619f60ae9a72a4036dbcbeb06519e9c3c6f47216ab4650f0c15955a45be0ae2ace13a0a2c92f6066e106fa6073b6c795ff808cc90854f85a1ad9e76
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_schemer (0.2.22)
4
+ json_schemer (0.2.24)
5
5
  ecma-re-validator (~> 0.3)
6
6
  hana (~> 1.3)
7
7
  regexp_parser (~> 2.0)
@@ -15,7 +15,7 @@ GEM
15
15
  hana (1.3.7)
16
16
  minitest (5.15.0)
17
17
  rake (13.0.6)
18
- regexp_parser (2.3.1)
18
+ regexp_parser (2.6.1)
19
19
  uri_template (0.7.0)
20
20
 
21
21
  PLATFORMS
@@ -28,4 +28,4 @@ DEPENDENCIES
28
28
  rake (~> 13.0)
29
29
 
30
30
  BUNDLED WITH
31
- 2.3.11
31
+ 2.3.25
@@ -44,6 +44,9 @@ module JSONSchemer
44
44
  end
45
45
  end
46
46
 
47
+ JSON_POINTER_TOKEN_ESCAPE_CHARS = { '~' => '~0', '/' => '~1' }
48
+ JSON_POINTER_TOKEN_ESCAPE_REGEXP = Regexp.union(JSON_POINTER_TOKEN_ESCAPE_CHARS.keys)
49
+
47
50
  def initialize(
48
51
  schema,
49
52
  format: true,
@@ -416,7 +419,7 @@ module JSONSchemer
416
419
 
417
420
  yield error(instance, 'maxLength') if max_length && data.size > max_length
418
421
  yield error(instance, 'minLength') if min_length && data.size < min_length
419
- yield error(instance, 'pattern') if pattern && resolve_regexp(pattern) !~ data
422
+ yield error(instance, 'pattern') if pattern && !resolve_regexp(pattern).match?(data)
420
423
  yield error(instance, 'format') if format? && spec_format?(format) && !valid_spec_format?(data, format)
421
424
 
422
425
  if content_encoding || content_media_type
@@ -531,7 +534,8 @@ module JSONSchemer
531
534
  dependencies.each do |key, value|
532
535
  next unless data.key?(key)
533
536
  subschema = value.is_a?(Array) ? { 'required' => value } : value
534
- subinstance = instance.merge(schema: subschema, schema_pointer: "#{instance.schema_pointer}/dependencies/#{key}")
537
+ escaped_key = escape_json_pointer_token(key)
538
+ subinstance = instance.merge(schema: subschema, schema_pointer: "#{instance.schema_pointer}/dependencies/#{escaped_key}")
535
539
  validate_instance(subinstance, &block)
536
540
  end
537
541
  end
@@ -545,6 +549,8 @@ module JSONSchemer
545
549
 
546
550
  regex_pattern_properties = nil
547
551
  data.each do |key, value|
552
+ escaped_key = escape_json_pointer_token(key)
553
+
548
554
  unless property_names.nil?
549
555
  subinstance = instance.merge(
550
556
  data: key,
@@ -559,9 +565,9 @@ module JSONSchemer
559
565
  if properties && properties.key?(key)
560
566
  subinstance = instance.merge(
561
567
  data: value,
562
- data_pointer: "#{instance.data_pointer}/#{key}",
568
+ data_pointer: "#{instance.data_pointer}/#{escaped_key}",
563
569
  schema: properties[key],
564
- schema_pointer: "#{instance.schema_pointer}/properties/#{key}"
570
+ schema_pointer: "#{instance.schema_pointer}/properties/#{escaped_key}"
565
571
  )
566
572
  validate_instance(subinstance, &block)
567
573
  matched_key = true
@@ -572,12 +578,13 @@ module JSONSchemer
572
578
  [pattern, resolve_regexp(pattern), property_schema]
573
579
  end
574
580
  regex_pattern_properties.each do |pattern, regex, property_schema|
581
+ escaped_pattern = escape_json_pointer_token(pattern)
575
582
  if regex.match?(key)
576
583
  subinstance = instance.merge(
577
584
  data: value,
578
- data_pointer: "#{instance.data_pointer}/#{key}",
585
+ data_pointer: "#{instance.data_pointer}/#{escaped_key}",
579
586
  schema: property_schema,
580
- schema_pointer: "#{instance.schema_pointer}/patternProperties/#{pattern}"
587
+ schema_pointer: "#{instance.schema_pointer}/patternProperties/#{escaped_pattern}"
581
588
  )
582
589
  validate_instance(subinstance, &block)
583
590
  matched_key = true
@@ -590,7 +597,7 @@ module JSONSchemer
590
597
  unless additional_properties.nil?
591
598
  subinstance = instance.merge(
592
599
  data: value,
593
- data_pointer: "#{instance.data_pointer}/#{key}",
600
+ data_pointer: "#{instance.data_pointer}/#{escaped_key}",
594
601
  schema: additional_properties,
595
602
  schema_pointer: "#{instance.schema_pointer}/additionalProperties"
596
603
  )
@@ -614,6 +621,10 @@ module JSONSchemer
614
621
  nil
615
622
  end
616
623
 
624
+ def escape_json_pointer_token(token)
625
+ token.gsub(JSON_POINTER_TOKEN_ESCAPE_REGEXP, JSON_POINTER_TOKEN_ESCAPE_CHARS)
626
+ end
627
+
617
628
  def join_uri(a, b)
618
629
  b = URI.parse(b) if b
619
630
  if a && b && a.relative? && b.relative?
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module JSONSchemer
3
- VERSION = '0.2.22'
3
+ VERSION = '0.2.24'
4
4
  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.2.22
4
+ version: 0.2.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Harsha
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-27 00:00:00.000000000 Z
11
+ date: 2022-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler