json_schemer 0.2.23 → 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: 1c55d246b024978c9c972889597f5224da512f7452e67369e9164264be0c809e
4
- data.tar.gz: e08104af62466e8c05c03091b1c14f01d28ea8be255a363ae13c88dbe450423c
3
+ metadata.gz: 24ab3d7f62a2ca93d0dcd3fb33191de983006b504d7bdae60066268fabf7eb50
4
+ data.tar.gz: 5f695dffd93a834e81491d5a5b328e6b193d56886666533e6ec0c5e7ba5b5be0
5
5
  SHA512:
6
- metadata.gz: be1e817cf98bcdcfe89c7e798475e23cb6961e0523691e950a1c3ed8b3e34357d949bc63b7096ed8cb29c966b0bd16b9aa29ef674bd26e6b302a849a09aaa7ee
7
- data.tar.gz: 590e048ad223135c9634a3e12036cbc83f2a6773143df22f4c7f56e19f228fd56e4425a07302c0d30e4c0aa6e6a94fd255ec15ebd0e59d8a568922110a9b9d55
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.23)
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.6.0)
18
+ regexp_parser (2.6.1)
19
19
  uri_template (0.7.0)
20
20
 
21
21
  PLATFORMS
@@ -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,
@@ -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.23'
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.23
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-11-03 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