canon 0.3.16 → 0.3.18
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 +4 -4
- data/lib/canon/comparison/ruby_object_comparator.rb +9 -0
- data/lib/canon/formatters/json_formatter.rb +6 -2
- data/lib/canon/formatters/yaml_formatter.rb +6 -2
- data/lib/canon/html/data_model.rb +1 -2
- data/lib/canon/version.rb +1 -1
- data/lib/canon/xml/whitespace_policy.rb +7 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b27c3659e1b75307f170fb50161ce649c54ab4a12600716d3b006fce8b01ad1a
|
|
4
|
+
data.tar.gz: 89c288d724f4a3b0b410938d94959880b4fbbcff1ec550b53593840bd33d52c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0922a2a6d6061f7472ac55de8c6e0172a8ce8d2939f8f144f71493b148248fb597c07d916c67dc9a4549d35a6e65b7757e5cb3f0d0ae79a7a39f7b35306bbb22'
|
|
7
|
+
data.tar.gz: e5b5b898ca11ef0bdc077d8cfb78d6575bc7c9a6b712f2a0ccbd2a3f338704d66883c730e32651af1776746b751b996c723b29af80044d8cd44944f9b18df883
|
|
@@ -24,6 +24,15 @@ module Canon
|
|
|
24
24
|
return Comparison::UNEQUAL_TYPES
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# FAST PATH: deep-equal objects in identical key order — every
|
|
28
|
+
# nested comparison is trivially equivalent and no key-order
|
|
29
|
+
# difference exists (strict key_order compares insertion
|
|
30
|
+
# order, which keys == keys preserves). Most object pairs in
|
|
31
|
+
# similar documents hit this and skip the path-building walk.
|
|
32
|
+
if obj1 == obj2 && (!obj1.is_a?(Hash) || obj1.keys == obj2.keys)
|
|
33
|
+
return Comparison::EQUIVALENT
|
|
34
|
+
end
|
|
35
|
+
|
|
27
36
|
case obj1
|
|
28
37
|
when Hash
|
|
29
38
|
compare_hashes(obj1, obj2, opts, differences, path)
|
|
@@ -23,8 +23,12 @@ module Canon
|
|
|
23
23
|
def self.sort_json_keys(obj)
|
|
24
24
|
case obj
|
|
25
25
|
when Hash
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
# Single pass: sorted keys once, one rebuilt hash. The
|
|
27
|
+
# previous form (transform_values + sort.to_h) rebuilt every
|
|
28
|
+
# container twice per canonicalization.
|
|
29
|
+
sorted = {}
|
|
30
|
+
obj.keys.sort.each { |key| sorted[key] = sort_json_keys(obj[key]) }
|
|
31
|
+
sorted
|
|
28
32
|
when Array
|
|
29
33
|
obj.map { |item| sort_json_keys(item) }
|
|
30
34
|
else
|
|
@@ -23,8 +23,12 @@ module Canon
|
|
|
23
23
|
def self.sort_yaml_keys(obj)
|
|
24
24
|
case obj
|
|
25
25
|
when Hash
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
# Single pass: sorted keys once, one rebuilt hash (the
|
|
27
|
+
# transform_values + sort.to_h form rebuilt every container
|
|
28
|
+
# twice).
|
|
29
|
+
sorted = {}
|
|
30
|
+
obj.keys.sort.each { |key| sorted[key] = sort_yaml_keys(obj[key]) }
|
|
31
|
+
sorted
|
|
28
32
|
when Array
|
|
29
33
|
obj.map { |item| sort_yaml_keys(item) }
|
|
30
34
|
else
|
|
@@ -134,8 +134,7 @@ module Canon
|
|
|
134
134
|
keep: Canon::Xml::WhitespacePolicy.keep_html_text?(
|
|
135
135
|
node.content,
|
|
136
136
|
parent_name: node.parent.is_a?(Nokogiri::XML::Element) ? node.parent.name : nil,
|
|
137
|
-
|
|
138
|
-
Canon::Comparison::WhitespaceSensitivity.inline_whitespace_significant?(node),
|
|
137
|
+
text_node: node,
|
|
139
138
|
),
|
|
140
139
|
)
|
|
141
140
|
when Nokogiri::XML::Comment
|
data/lib/canon/version.rb
CHANGED
|
@@ -61,13 +61,18 @@ element_parent: true)
|
|
|
61
61
|
# so it is checked explicitly).
|
|
62
62
|
HTML_WHITESPACE_SENSITIVE_TAGS = %w[pre code textarea script style].freeze
|
|
63
63
|
|
|
64
|
-
def keep_html_text?(content, parent_name:,
|
|
64
|
+
def keep_html_text?(content, parent_name:, text_node: nil)
|
|
65
65
|
return true unless content.match?(STRIP_ONLY)
|
|
66
66
|
return true if content.include?(" ")
|
|
67
67
|
|
|
68
68
|
parent_name = parent_name.to_s.downcase
|
|
69
69
|
return true if HTML_WHITESPACE_SENSITIVE_TAGS.include?(parent_name)
|
|
70
|
-
|
|
70
|
+
|
|
71
|
+
# Computed last: the sibling scan is O(siblings), so it must
|
|
72
|
+
# not run for the content-bearing text nodes that fail the
|
|
73
|
+
# whitespace-only check above.
|
|
74
|
+
return true if text_node &&
|
|
75
|
+
Canon::Comparison::WhitespaceSensitivity.inline_whitespace_significant?(text_node)
|
|
71
76
|
|
|
72
77
|
false
|
|
73
78
|
end
|