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 +4 -4
- data/lib/canon/version.rb +1 -1
- data/lib/canon/xml/c14n.rb +39 -13
- 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: 8180f10b0965070c408985ca44868fc14ae2256f24dac607492470aea7e5d076
|
|
4
|
+
data.tar.gz: e50498b713b972237a67af3b3f5c2cd5fb0cf1cbc3fef0dbb57f628810ce2341
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52c5eb3fcb8ab3e09c7de5b8b7120f2baad191467aeccab6154254cd0007128f76ae2f5dbd26102abf19c3cf9f289f3c0445db88917562d7b7edafe9aef7ae5b
|
|
7
|
+
data.tar.gz: 373032bcba62f9685c41f09bb0d3dce294c50fa8785252e3737231a67f9a0fdfdb5372c85f3b28da5983faf39d4cdf89723dfae8397969511d2688afecaf3418
|
data/lib/canon/version.rb
CHANGED
data/lib/canon/xml/c14n.rb
CHANGED
|
@@ -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)
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
# (
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
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
|
|