canon 0.3.46 → 0.3.47

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: 2dc57b150c1a0a2b9179f4b88a78c22aeb1529aa74d30857d8ca71a6159d6639
4
- data.tar.gz: 65db8a7cadb8718b11a475858d3bfd5d4adcf0a4c738a7c940a6dfa60a6bfd3e
3
+ metadata.gz: 8180f10b0965070c408985ca44868fc14ae2256f24dac607492470aea7e5d076
4
+ data.tar.gz: e50498b713b972237a67af3b3f5c2cd5fb0cf1cbc3fef0dbb57f628810ce2341
5
5
  SHA512:
6
- metadata.gz: d411dc92e7978a904f303a95397f301286e9a12a3fc3732bb91919c2564375221b12cb13db64198f41942edeb5bbe2dfc8512b173cbfbdab44d27409d5a009a9
7
- data.tar.gz: eaa339eae29ca147aa6ee9a5cecf9a328e69fc9b1f64b3acb742d11f4d451bef89efc11cde012e06e15f21b10ec09f95fbf36e0456c718ba925c015e47dba0ce
6
+ metadata.gz: 52c5eb3fcb8ab3e09c7de5b8b7120f2baad191467aeccab6154254cd0007128f76ae2f5dbd26102abf19c3cf9f289f3c0445db88917562d7b7edafe9aef7ae5b
7
+ data.tar.gz: 373032bcba62f9685c41f09bb0d3dce294c50fa8785252e3737231a67f9a0fdfdb5372c85f3b28da5983faf39d4cdf89723dfae8397969511d2688afecaf3418
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.46"
4
+ VERSION = "0.3.47"
5
5
  end
@@ -23,19 +23,24 @@ module Canon
23
23
  end
24
24
 
25
25
  # leptris' C-side C14N 1.1 — 23x faster than the Ruby processor
26
- # through canon's own API (1MB document). libleptris 1.9.164
27
- # closed four of the five leptris#1015 families (attribute
28
- # ordering, prefix loss and rebinding, `>` and TAB escaping —
29
- # unpinned in the parity spec since gem 1.9.174.0). A local
30
- # default-flip attempt surfaced three MORE divergences the
31
- # edge corpus did not cover, so the lane stays opt-in
32
- # (CANON_C14N_BACKEND=leptris) until they close (leptris#1096):
33
- # redundant namespace redeclarations are kept (Ruby removes
34
- # them), xmlns:xml with the standard URI is kept (Ruby omits
35
- # it), and document-level processing instructions are dropped.
36
- # The Ruby lane additionally validates relative namespace URIs
37
- # at parse time a future flip must carry that check into the
38
- # native wrapper. Comments mode keeps the Ruby path regardless.
26
+ # through canon's own API (1MB document) and byte-identical on
27
+ # the parity corpus, but OPT-IN (CANON_C14N_BACKEND=leptris)
28
+ # pending three families verified against libxml2 ground truth
29
+ # (leptris#1096 follow-up): (1) whitespace-only text between
30
+ # elements is preserved the Ruby lane's parse drops it and
31
+ # compact bytes are canon's product for every pretty-printed
32
+ # document; (2) whitespace-only processing-instruction data is
33
+ # retained (libxml2 drops it); (3) document-level nodes carry
34
+ # no "\n" separators (the Ruby lane, like libxml2, inserts
35
+ # them). libleptris 1.9.176/177 (gem 1.9.177.0) closed the
36
+ # earlier families attribute ordering, prefix loss and
37
+ # rebinding, `>`/TAB escaping, redundant namespace
38
+ # redeclarations, xmlns:xml omission and document-level PIs
39
+ # now serialize in document order (the Ruby processor's
40
+ # root-first order is non-conformant for prolog PIs).
41
+ # Relative namespace URIs raise exactly as the Ruby lane does.
42
+ # Comments mode keeps the Ruby path (the native seam exposes no
43
+ # with-comments form).
39
44
  def self.native_canonicalize(xml, with_comments)
40
45
  return nil if with_comments
41
46
  return nil if RUBY_ENGINE == "opal"
@@ -44,6 +49,8 @@ module Canon
44
49
  Canon::XmlParsing.moxml_adapter_name == :leptris
45
50
  return nil unless native_c14n_available?
46
51
 
52
+ validate_relative_namespaces!(xml)
53
+
47
54
  doc = Canon::XmlParsing.moxml_context.parse(xml, readonly: true,
48
55
  strict: false)
49
56
  begin
@@ -58,6 +65,25 @@ module Canon
58
65
  nil
59
66
  end
60
67
 
68
+ # Canon::Error parity with the Ruby lane, whose parse rejects
69
+ # relative namespace URIs. A declaration-shaped scan; a
70
+ # relative-URI-shaped string inside CDATA is the only false
71
+ # positive this can produce.
72
+ RELATIVE_NS_DECL = /xmlns(?::[\w.-]+)?="([^"]*)"/
73
+ URI_SCHEME = %r{\A[a-zA-Z][a-zA-Z0-9+.-]*:}
74
+
75
+ def self.validate_relative_namespaces!(xml)
76
+ return unless xml.is_a?(String)
77
+
78
+ xml.scan(RELATIVE_NS_DECL) do |(uri)|
79
+ next if uri.nil? || uri.empty?
80
+
81
+ unless uri.match?(URI_SCHEME)
82
+ raise Canon::Error, "Relative namespace URI not allowed: #{uri}"
83
+ end
84
+ end
85
+ end
86
+
61
87
  def self.native_c14n_available?
62
88
  return @native_c14n_available unless @native_c14n_available.nil?
63
89
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.46
4
+ version: 0.3.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.