xml-c14n 0.2.0 → 0.2.1
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/.rubocop.yml +10 -0
- data/README.adoc +11 -1
- data/lib/xml/c14n/rspec_matchers.rb +66 -0
- data/lib/xml/c14n/version.rb +1 -1
- data/lib/xml/c14n.rb +19 -24
- metadata +31 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db7534268066a77ae26796e4968ffd0c597918f84e7ba9e28c030d7fcb40e944
|
4
|
+
data.tar.gz: 5df2c8751d1e510dc03256b75d7bbb4377f872f8ec4697464682dbf8f4af25bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba62dceb49d17fab2de11b0362f2497cb0465495e82d0a1ee66d612780e0ab92596ae444da2bb0d15261d47db0288b13b34c87bdda2f0864b6055c355989568a
|
7
|
+
data.tar.gz: 7e9bb5d2f596573efe588ec43d6632451b15b2f7314111ccb247f81dcb79d18e08058704e454ada56dd3062481b0c88ac983c25e1574905f80edd782ace49af1
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
inherit_from:
|
4
|
+
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
5
|
+
|
6
|
+
# local repo-specific modifications
|
7
|
+
# ...
|
8
|
+
|
9
|
+
AllCops:
|
10
|
+
TargetRubyVersion: 2.7
|
data/README.adoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= XML pretty-print / canonicalizer
|
1
|
+
= XML pretty-print / canonicalizer / RSpec comparator
|
2
2
|
|
3
3
|
== Purpose
|
4
4
|
|
@@ -7,6 +7,9 @@ to pretty-print and provide a canonicalized form of XML
|
|
7
7
|
(https://www.w3.org/TR/xml-c14n11/[W3C Canonicalized XML]) suitable
|
8
8
|
for signing and comparison.
|
9
9
|
|
10
|
+
This gem also provides the RSpec matcher `be_analogous_with` for comparing XML
|
11
|
+
content. The matcher used is from the
|
12
|
+
https://github.com/vkononov/compare-xml[`compare-xml`] gem.
|
10
13
|
|
11
14
|
== Usage
|
12
15
|
|
@@ -34,6 +37,13 @@ it "canonicalizes #{File.basename(f)}" do
|
|
34
37
|
|
35
38
|
expect(output).to eq(input)
|
36
39
|
end
|
40
|
+
|
41
|
+
it "checks if analogous with #{File.basename(f)}" do
|
42
|
+
input = Xml::C14n.format(File.read(xml_raw))
|
43
|
+
output = Xml::C14n.format(File.read(xml_c14n))
|
44
|
+
|
45
|
+
expect(output).to be_analogous_with(input)
|
46
|
+
end
|
37
47
|
----
|
38
48
|
|
39
49
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "xml-c14n" unless defined?(::Xml::C14n)
|
4
|
+
require "compare-xml"
|
5
|
+
|
6
|
+
begin
|
7
|
+
require "rspec/expectations"
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
module Xml
|
12
|
+
module C14n
|
13
|
+
module RSpecMatchers
|
14
|
+
class AnalogousMatcher
|
15
|
+
def initialize(expected)
|
16
|
+
@expected = expected
|
17
|
+
@result = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def matches?(target)
|
21
|
+
@target = target
|
22
|
+
|
23
|
+
@result = CompareXML.equivalent?(
|
24
|
+
Nokogiri::XML(@target),
|
25
|
+
Nokogiri::XML(@expected),
|
26
|
+
{ collapse_whitespace: true,
|
27
|
+
ignore_attr_order: true,
|
28
|
+
verbose: true },
|
29
|
+
)
|
30
|
+
|
31
|
+
@result.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def failure_message
|
35
|
+
index = 0
|
36
|
+
@result.map do |hash|
|
37
|
+
index += 1
|
38
|
+
"DIFF #{index}: expected node: #{hash[:node1]}\n" \
|
39
|
+
" actual node : #{hash[:node2]}\n" \
|
40
|
+
" diff from : #{hash[:diff1]}\n" \
|
41
|
+
" diff to : #{hash[:diff2]}\n"
|
42
|
+
end.join("\n")
|
43
|
+
end
|
44
|
+
|
45
|
+
def failure_message_when_negated
|
46
|
+
["expected:", @target.to_s, "not be analogous with:",
|
47
|
+
@expected.to_s].join("\n")
|
48
|
+
end
|
49
|
+
|
50
|
+
def diffable
|
51
|
+
true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def be_analogous_with(expected)
|
56
|
+
AnalogousMatcher.new(expected)
|
57
|
+
end
|
58
|
+
|
59
|
+
if defined?(::RSpec)
|
60
|
+
RSpec.configure do |config|
|
61
|
+
config.include(Xml::C14n::RSpecMatchers)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/xml/c14n/version.rb
CHANGED
data/lib/xml/c14n.rb
CHANGED
@@ -3,13 +3,17 @@
|
|
3
3
|
require_relative "c14n/version"
|
4
4
|
require "nokogiri"
|
5
5
|
|
6
|
+
require_relative "c14n/rspec_matchers" if defined?(::RSpec)
|
7
|
+
|
6
8
|
module Xml
|
9
|
+
# C14n stands for canonicalization
|
7
10
|
module C14n
|
11
|
+
# Source of XSLT
|
12
|
+
# https://emmanueloga.wordpress.com/2009/09/29/pretty-printing-xhtml-with-nokogiri-and-xslt/
|
8
13
|
NOKOGIRI_C14N_XSL = <<~XSL
|
9
14
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
10
15
|
<xsl:output method="xml" encoding="ISO-8859-1"/>
|
11
16
|
<xsl:param name="indent-increment" select="' '"/>
|
12
|
-
|
13
17
|
<xsl:template name="newline">
|
14
18
|
<xsl:text disable-output-escaping="yes">
|
15
19
|
</xsl:text>
|
@@ -35,38 +39,29 @@ module Xml
|
|
35
39
|
<xsl:param name="indent" select="''"/>
|
36
40
|
<xsl:call-template name="newline"/>
|
37
41
|
<xsl:value-of select="$indent"/>
|
38
|
-
|
39
|
-
|
42
|
+
<xsl:choose>
|
43
|
+
<xsl:when test="count(child::*) > 0">
|
40
44
|
<xsl:copy>
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
<xsl:copy-of select="@*"/>
|
46
|
+
<xsl:apply-templates select="*|text()">
|
47
|
+
<xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
|
48
|
+
</xsl:apply-templates>
|
49
|
+
<xsl:call-template name="newline"/>
|
50
|
+
<xsl:value-of select="$indent"/>
|
47
51
|
</xsl:copy>
|
48
|
-
|
49
|
-
|
52
|
+
</xsl:when>
|
53
|
+
<xsl:otherwise>
|
50
54
|
<xsl:copy-of select="."/>
|
51
|
-
|
52
|
-
|
55
|
+
</xsl:otherwise>
|
56
|
+
</xsl:choose>
|
53
57
|
</xsl:template>
|
54
58
|
</xsl:stylesheet>
|
55
59
|
XSL
|
56
|
-
# NOKOGIRI_C14N_XSL = <<~XSL
|
57
|
-
# <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
58
|
-
# <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
|
59
|
-
# <xsl:strip-space elements="*"/>
|
60
|
-
# <xsl:template match="/">
|
61
|
-
# <xsl:copy-of select="."/>
|
62
|
-
# </xsl:template>
|
63
|
-
# </xsl:stylesheet>
|
64
|
-
# XSL
|
65
60
|
|
66
61
|
def self.format(xml)
|
67
62
|
Nokogiri::XSLT(NOKOGIRI_C14N_XSL)
|
68
|
-
|
69
|
-
|
63
|
+
.transform(Nokogiri::XML(xml, &:noblanks))
|
64
|
+
.to_xml(indent: 2, pretty: true, encoding: "UTF-8")
|
70
65
|
end
|
71
66
|
|
72
67
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml-c14n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: compare-xml
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: nokogiri
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-performance
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: Library for XML canonicalization
|
70
98
|
email:
|
71
99
|
- open.source@ribose.com
|
@@ -74,11 +102,13 @@ extensions: []
|
|
74
102
|
extra_rdoc_files: []
|
75
103
|
files:
|
76
104
|
- ".rspec"
|
105
|
+
- ".rubocop.yml"
|
77
106
|
- CODE_OF_CONDUCT.md
|
78
107
|
- README.adoc
|
79
108
|
- Rakefile
|
80
109
|
- lib/xml-c14n.rb
|
81
110
|
- lib/xml/c14n.rb
|
111
|
+
- lib/xml/c14n/rspec_matchers.rb
|
82
112
|
- lib/xml/c14n/version.rb
|
83
113
|
- sig/xml/c14n.rbs
|
84
114
|
homepage: https://github.com/metanorma/xml-c14n
|