canon 0.3.109 → 0.3.111

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: ebfe19fb1f87ac9ec65e4fc2ba727bbe97b3b8d0f9733184588217e82753e9f9
4
- data.tar.gz: 301b3d96f9ffebce87022cdfef4d538ab512ea6f832bdfd3f2c39c164a996069
3
+ metadata.gz: 88e8f69b4949d642507ea1039ab45a14273b42a806fbf2198444a0dd3ded62ae
4
+ data.tar.gz: be39473082b9bdf3b32174a6bd217face312dd0e2872fec990ca5f6bf3d54c7e
5
5
  SHA512:
6
- metadata.gz: cb97c29a9ab623568ac2ea936710a42694b7d4863e0075ee90dce47f3ff01faba53a695e66abde1ce680ef3d53da4e31a7c9b8ed9a6f883dac08d48dc3757c66
7
- data.tar.gz: e4b4a46d00abe224d9bf541cc248220aa984caec768f3d2173be3b00c8471234141ae872dbc6273445b3be6434c8a027ad98e8ffba1045b8a712ee54bf2d8f35
6
+ metadata.gz: 68c47754c52898a62221e489896ece0ca5dc2560d3821683b4404d823fb80d26f4513be7475ecbf2b2846c26e27a84b0d1d2aa3420ffdde2b6071d5dc5e31e6a
7
+ data.tar.gz: 5b4b67fa6dbeb20764fc40c1d747597b41c6829e575506bbc915fb567036b0b2c33969f3ff01f7ccb414785aa79bb078f7273bec09f29cf58ff2ceec039063cc
@@ -198,6 +198,12 @@ module Canon
198
198
  )
199
199
  has_mismatch = false
200
200
 
201
+ # The ORIGINAL direction, captured before
202
+ # determine_mismatch_children returns reduced sets of equal
203
+ # length — deriving the side from the reduced sets reports
204
+ # every mid-content removal as an insertion (canon#285).
205
+ before_longer = children1.length > children2.length
206
+
201
207
  # Length check
202
208
  unless children1.length == children2.length
203
209
  has_mismatch = true
@@ -228,7 +234,7 @@ module Canon
228
234
  else
229
235
  mismatched_children.each do |child|
230
236
  child_dim = comparator.determine_node_dimension(child)
231
- if children1.length > children2.length
237
+ if before_longer
232
238
  comparator.add_difference(child, nil,
233
239
  Comparison::MISSING_NODE,
234
240
  Comparison::MISSING_NODE,
@@ -9,6 +9,14 @@ module Canon
9
9
  def self.format(json)
10
10
  parsed = parse(json)
11
11
  JSON.pretty_generate(sort_json_keys(parsed))
12
+ rescue JSON::GeneratorError => e
13
+ # overflow numbers parse to ±Infinity, which JSON cannot
14
+ # represent: the rejection is canon's, so raise own error
15
+ # (the i_number_real_*_overflow corpus family)
16
+ raise Canon::ValidationError.new(
17
+ "JSON cannot represent #{e.message[/\S+/]}: number out of range",
18
+ format: :json,
19
+ )
12
20
  end
13
21
 
14
22
  def self.parse(json)
@@ -25,9 +25,14 @@ module Canon
25
25
  when Hash
26
26
  # Single pass: sorted keys once, one rebuilt hash (the
27
27
  # transform_values + sort.to_h form rebuilt every container
28
- # twice).
28
+ # twice). YAML mapping keys are heterogeneous by nature
29
+ # (strings, symbols, integers, nil, complex collections) —
30
+ # the canonical order is the TOTAL order over [class, to_s];
31
+ # homogeneous String keys sort exactly as before.
29
32
  sorted = {}
30
- obj.keys.sort.each { |key| sorted[key] = sort_yaml_keys(obj[key]) }
33
+ obj.keys.sort_by { |key| [key.class.name, key.to_s] }.each do |key|
34
+ sorted[key] = sort_yaml_keys(obj[key])
35
+ end
31
36
  sorted
32
37
  when Array
33
38
  obj.map { |item| sort_yaml_keys(item) }
@@ -18,6 +18,15 @@ module Canon
18
18
  def self.validate!(input)
19
19
  return if input.nil?
20
20
  return if input.is_a?(Hash) || input.is_a?(Array) # Already parsed
21
+ # The malformed-bytes corpus (JSONTestSuite n_*) carries
22
+ # invalid UTF-8: strip/compare would raise
23
+ # Encoding::CompatibilityError instead of a validation error
24
+ unless input.valid_encoding?
25
+ raise Canon::ValidationError.new(
26
+ "invalid byte sequence in #{input.encoding}",
27
+ format: :json,
28
+ )
29
+ end
21
30
  return if input.strip.empty?
22
31
 
23
32
  Canon::JsonParsing.parse(input)
data/lib/canon/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Canon
4
- VERSION = "0.3.109"
4
+ VERSION = "0.3.111"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.109
4
+ version: 0.3.111
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-22 00:00:00.000000000 Z
11
+ date: 2026-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs