canon 0.3.127 → 0.3.128

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: 6b85f7ce86318586f09a582f550e6045638f89fa45f39b13b779cfc460dcbed4
4
- data.tar.gz: 7447ff0c266c542501be52e56dfa7afc868c23e7143893a78b9b322f3751e978
3
+ metadata.gz: 05b7c9d8d7d816829876353d38c9f7fbbfef712f58fe99977d90558a3b99616f
4
+ data.tar.gz: f23c9e92162577d39fdb7843ee724f9b0f6f9378978e2d8813df6888d6fb72a8
5
5
  SHA512:
6
- metadata.gz: 5408428461d0606e7c2bd2081e88e05653fe39dbc541e5c9572a51125525f645262428b9f00edb353d3fc4942deec732e015345e40cba8e37224f0953c83845d
7
- data.tar.gz: 89a42a0501c99ec47455f7bd76eb1214514c4710af64a4e470ae5708392c86c97b9a47f7b6dde30ae8106b5202d2c544fe140261018177da923a76f8c0e018af
6
+ metadata.gz: bf24d1fc69d40ad4e4049cc874cfb499cfba8a88eda02fad1bf9625a7b8269559d5652b4f94df69f342cf280442a770819cfb9d3bb0267de759877b254ddafc5
7
+ data.tar.gz: 1f03fb807aa7242b01c268bf5c847ce0d67658a3b7677b7dd9fbddc468ba488c6a4aa89b689f7938e161f7edc42cfd98b6e4d4ec468ba4e75e74e364ce172224
@@ -59,9 +59,14 @@ module Canon
59
59
  when :attribute_values
60
60
  build_attribute_values_reason(node1, node2)
61
61
  when :text_content
62
- build_text_difference_reason(
63
- extract_text_content(node1), extract_text_content(node2)
64
- )
62
+ if NodeInspector.processing_instruction_node?(node1) &&
63
+ NodeInspector.processing_instruction_node?(node2)
64
+ build_pi_difference_reason(node1, node2)
65
+ else
66
+ build_text_difference_reason(
67
+ extract_text_content(node1), extract_text_content(node2)
68
+ )
69
+ end
65
70
  when :attribute_order
66
71
  build_attribute_order_reason(node1, node2)
67
72
  when :comments
@@ -191,6 +196,23 @@ module Canon
191
196
  "Text: \"#{visualize_whitespace(text1)}\" vs \"#{visualize_whitespace(text2)}\""
192
197
  end
193
198
 
199
+ # --- Processing instruction reason -------------------------------------
200
+
201
+ # PIs have no text content, so the text-difference reason would
202
+ # report "whitespace: 0 chars vs 0 chars" for genuinely different
203
+ # PIs (canon#318). The serialized form carries target and data.
204
+ def self.build_pi_difference_reason(node1, node2)
205
+ t1, d1 = NodeInspector.processing_instruction_parts(node1)
206
+ t2, d2 = NodeInspector.processing_instruction_parts(node2)
207
+
208
+ if t1 != t2
209
+ return "Processing instruction target differs: <?#{t1}?> vs <?#{t2}?>"
210
+ end
211
+
212
+ "Processing instruction data differs: " \
213
+ "<?#{t1} #{d1}?> vs <?#{t2} #{d2}?>"
214
+ end
215
+
194
216
  # --- Comment reason ----------------------------------------------------
195
217
 
196
218
  def self.build_comment_difference_reason(node1, node2)
@@ -56,6 +56,25 @@ module Canon
56
56
  end
57
57
  end
58
58
 
59
+ def self.processing_instruction_node?(node)
60
+ return false unless node
61
+ return node.node_type == :processing_instruction if node.is_a?(Canon::Xml::Node)
62
+
63
+ XmlParsing.processing_instruction?(node)
64
+ end
65
+
66
+ # [target, data] of a processing instruction. Canon PI nodes carry
67
+ # them natively; backend PIs expose the target as the node name
68
+ # and the data as the content (moxml #text is empty for PIs).
69
+ def self.processing_instruction_parts(node)
70
+ if node.is_a?(Canon::Xml::Nodes::ProcessingInstructionNode)
71
+ [node.target.to_s, node.data.to_s]
72
+ else
73
+ [XmlParsing.processing_instruction_target(node),
74
+ XmlParsing.processing_instruction_data(node)]
75
+ end
76
+ end
77
+
59
78
  def self.document?(node)
60
79
  return node.node_type == :root if node.is_a?(Canon::Xml::Node)
61
80
 
@@ -357,6 +357,15 @@ expand_difference: false)
357
357
  return format_text_content_one_sided(node1, node2, use_color)
358
358
  end
359
359
 
360
+ # Document-level PIs have empty text content; the ambiguous-pair
361
+ # parent fallback below would serialize the document node and
362
+ # render the whole document as the diff payload (canon#318).
363
+ # The PIs' own serialized forms are the informative view.
364
+ if Canon::Comparison::NodeInspector.processing_instruction_node?(node1) &&
365
+ Canon::Comparison::NodeInspector.processing_instruction_node?(node2)
366
+ return format_pi_content_details(node1, node2, use_color)
367
+ end
368
+
360
369
  text1 = NodeUtils.node_to_display(node1, compact: compact)
361
370
  text2 = NodeUtils.node_to_display(node2, compact: compact)
362
371
 
@@ -414,6 +423,26 @@ expand_difference: false)
414
423
  [detail1, detail2, changes]
415
424
  end
416
425
 
426
+ # Processing-instruction content: the PIs' serialized forms
427
+ # (<?target data?>), whitespace-visualised like text content.
428
+ def self.format_pi_content_details(node1, node2, use_color)
429
+ t1, d1 = Canon::Comparison::NodeInspector.processing_instruction_parts(node1)
430
+ t2, d2 = Canon::Comparison::NodeInspector.processing_instruction_parts(node2)
431
+
432
+ detail1 = ColorHelper.colorize(
433
+ TextUtils.visualize_whitespace("<?#{t1} #{d1}?>".rstrip),
434
+ :red, use_color
435
+ )
436
+ detail2 = ColorHelper.colorize(
437
+ TextUtils.visualize_whitespace("<?#{t2} #{d2}?>".rstrip),
438
+ :green, use_color
439
+ )
440
+
441
+ changes = "Content differs: #{detail1} → #{detail2}"
442
+
443
+ [detail1, detail2, changes]
444
+ end
445
+
417
446
  # Whether a node is an element (Canon or Nokogiri), used to
418
447
  # detect element-shaped diffs that have been misclassified as
419
448
  # :text_content and route them to element-structure rendering.
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.127"
4
+ VERSION = "0.3.128"
5
5
  end
@@ -176,6 +176,18 @@ module Canon
176
176
  node.is_a?(Moxml::ProcessingInstruction)
177
177
  end
178
178
 
179
+ # The PI target ("rfc" in <?rfc strict="yes"?>) — the node name
180
+ # on every backend (Nokogiri PIs carry no #target accessor).
181
+ def processing_instruction_target(node)
182
+ name(node).to_s
183
+ end
184
+
185
+ # The PI data ('strict="yes"' in <?rfc strict="yes"?>) — the
186
+ # node content on every backend (moxml #text is empty for PIs).
187
+ def processing_instruction_data(node)
188
+ node.content.to_s
189
+ end
190
+
179
191
  def document_fragment?(obj)
180
192
  defined?(Nokogiri) && obj.is_a?(Nokogiri::XML::DocumentFragment)
181
193
  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.127
4
+ version: 0.3.128
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-11-15 00:00:00.000000000 Z
11
+ date: 2026-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs