canon 0.2.8 → 0.2.11
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/.rspec-opal +7 -0
- data/.rubocop_todo.yml +25 -73
- data/Rakefile +37 -0
- data/lib/canon/cache.rb +16 -27
- data/lib/canon/cli.rb +1 -1
- data/lib/canon/color_detector.rb +3 -5
- data/lib/canon/comparison/compare_profile.rb +1 -4
- data/lib/canon/comparison/dimensions/attribute_order_dimension.rb +2 -6
- data/lib/canon/comparison/dimensions/attribute_presence_dimension.rb +2 -6
- data/lib/canon/comparison/dimensions/attribute_values_dimension.rb +2 -6
- data/lib/canon/comparison/dimensions/comments_dimension.rb +2 -6
- data/lib/canon/comparison/dimensions/element_position_dimension.rb +2 -6
- data/lib/canon/comparison/dimensions/structural_whitespace_dimension.rb +2 -6
- data/lib/canon/comparison/dimensions/text_content_dimension.rb +3 -5
- data/lib/canon/comparison/format_detector.rb +29 -20
- data/lib/canon/comparison/html_comparator.rb +20 -29
- data/lib/canon/comparison/html_compare_profile.rb +3 -10
- data/lib/canon/comparison/html_parser.rb +1 -1
- data/lib/canon/comparison/json_comparator.rb +8 -0
- data/lib/canon/comparison/node_inspector.rb +117 -86
- data/lib/canon/comparison/strategies/semantic_tree_match_strategy.rb +6 -8
- data/lib/canon/comparison/whitespace_sensitivity.rb +55 -193
- data/lib/canon/comparison/xml_comparator/attribute_comparator.rb +19 -2
- data/lib/canon/comparison/xml_comparator/attribute_filter.rb +5 -10
- data/lib/canon/comparison/xml_comparator/child_comparison.rb +4 -4
- data/lib/canon/comparison/xml_comparator/diff_node_builder.rb +40 -8
- data/lib/canon/comparison/xml_comparator/namespace_comparator.rb +14 -28
- data/lib/canon/comparison/xml_comparator/node_parser.rb +14 -13
- data/lib/canon/comparison/xml_comparator/node_type_comparator.rb +30 -58
- data/lib/canon/comparison/xml_comparator.rb +63 -85
- data/lib/canon/comparison/xml_node_comparison.rb +15 -15
- data/lib/canon/comparison/yaml_comparator.rb +8 -0
- data/lib/canon/comparison.rb +24 -24
- data/lib/canon/config/profile_loader.rb +13 -13
- data/lib/canon/config.rb +29 -5
- data/lib/canon/diff/diff_classifier.rb +7 -41
- data/lib/canon/diff/diff_line.rb +1 -1
- data/lib/canon/diff/diff_line_builder.rb +2 -0
- data/lib/canon/diff/diff_node_enricher.rb +22 -24
- data/lib/canon/diff/diff_node_mapper.rb +10 -8
- data/lib/canon/diff/formatting_detector.rb +3 -2
- data/lib/canon/diff/node_serializer.rb +23 -30
- data/lib/canon/diff/path_builder.rb +24 -37
- data/lib/canon/diff/source_locator.rb +0 -3
- data/lib/canon/diff/xml_serialization_formatter.rb +8 -84
- data/lib/canon/diff_formatter/by_line/base_formatter.rb +7 -7
- data/lib/canon/diff_formatter/by_line/json_formatter.rb +1 -1
- data/lib/canon/diff_formatter/by_line/simple_formatter.rb +1 -1
- data/lib/canon/diff_formatter/by_line/xml_formatter.rb +2 -2
- data/lib/canon/diff_formatter/by_line/yaml_formatter.rb +1 -1
- data/lib/canon/diff_formatter/by_line_formatter.rb +1 -1
- data/lib/canon/diff_formatter/by_object/base_formatter.rb +23 -17
- data/lib/canon/diff_formatter/by_object/xml_formatter.rb +127 -11
- data/lib/canon/diff_formatter/by_object_formatter.rb +2 -6
- data/lib/canon/diff_formatter/debug_output.rb +12 -24
- data/lib/canon/diff_formatter/diff_detail_formatter/color_helper.rb +2 -2
- data/lib/canon/diff_formatter/diff_detail_formatter/dimension_formatter.rb +3 -3
- data/lib/canon/diff_formatter/diff_detail_formatter/location_extractor.rb +26 -27
- data/lib/canon/diff_formatter/diff_detail_formatter/node_utils.rb +146 -318
- data/lib/canon/diff_formatter/diff_detail_formatter.rb +28 -20
- data/lib/canon/diff_formatter/legend.rb +2 -2
- data/lib/canon/diff_formatter/pretty_diff_formatter.rb +2 -2
- data/lib/canon/diff_formatter/theme.rb +4 -4
- data/lib/canon/diff_formatter.rb +17 -13
- data/lib/canon/formatters/html_formatter.rb +1 -1
- data/lib/canon/formatters/html_formatter_base.rb +1 -1
- data/lib/canon/formatters/xml_formatter.rb +7 -32
- data/lib/canon/html/data_model.rb +2 -2
- data/lib/canon/pretty_printer/html.rb +1 -1
- data/lib/canon/pretty_printer/xml.rb +16 -7
- data/lib/canon/pretty_printer/xml_normalized.rb +9 -3
- data/lib/canon/rspec_matchers.rb +2 -2
- data/lib/canon/tree_diff/adapters/html_adapter.rb +1 -1
- data/lib/canon/tree_diff/adapters/xml_adapter.rb +1 -1
- data/lib/canon/tree_diff/core/tree_node.rb +1 -3
- data/lib/canon/tree_diff/operation_converter.rb +7 -7
- data/lib/canon/tree_diff/operations/operation_detector.rb +4 -0
- data/lib/canon/validators/base_validator.rb +5 -8
- data/lib/canon/validators/html_validator.rb +3 -8
- data/lib/canon/validators/xml_validator.rb +3 -8
- data/lib/canon/version.rb +1 -1
- data/lib/canon/xml/data_model.rb +132 -138
- data/lib/canon/xml/namespace_helper.rb +5 -0
- data/lib/canon/xml/node.rb +2 -1
- data/lib/canon/xml/nodes/root_node.rb +4 -0
- data/lib/canon/xml/nodes/text_node.rb +6 -1
- data/lib/canon/xml/sax_builder.rb +5 -7
- data/lib/canon/xml/whitespace_normalizer.rb +2 -2
- data/lib/canon/xml_backend.rb +49 -0
- data/lib/canon/xml_parsing.rb +283 -0
- data/lib/canon.rb +3 -1
- data/lib/tasks/benchmark_runner.rb +1 -1
- data/lib/tasks/performance_helpers.rb +1 -1
- metadata +9 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "unicode/name"
|
|
3
|
+
require "unicode/name" unless RUBY_ENGINE == "opal"
|
|
4
4
|
|
|
5
5
|
module Canon
|
|
6
6
|
class DiffFormatter
|
|
@@ -175,7 +175,7 @@ module Canon
|
|
|
175
175
|
|
|
176
176
|
require "rainbow"
|
|
177
177
|
presenter = Rainbow(text)
|
|
178
|
-
colors.each { |c| presenter = presenter.
|
|
178
|
+
colors.each { |c| presenter = presenter.public_send(c) }
|
|
179
179
|
presenter.to_s
|
|
180
180
|
end
|
|
181
181
|
|
|
@@ -797,19 +797,19 @@ _invalid_values)
|
|
|
797
797
|
return env_theme if env_theme
|
|
798
798
|
|
|
799
799
|
# Check config theme_inheritance (custom theme with base + overrides)
|
|
800
|
-
if @config.
|
|
800
|
+
if @config.is_a?(Canon::Config)
|
|
801
801
|
inheritance = @config.xml.diff.theme_inheritance
|
|
802
802
|
return resolve_inheritance_theme(inheritance) if inheritance
|
|
803
803
|
end
|
|
804
804
|
|
|
805
805
|
# Check config custom_theme (full custom theme hash)
|
|
806
|
-
if @config.
|
|
806
|
+
if @config.is_a?(Canon::Config)
|
|
807
807
|
custom = @config.xml.diff.custom_theme
|
|
808
808
|
return custom if custom.is_a?(Hash) && !custom.empty?
|
|
809
809
|
end
|
|
810
810
|
|
|
811
811
|
# Check config theme name
|
|
812
|
-
if @config.
|
|
812
|
+
if @config.is_a?(Canon::Config)
|
|
813
813
|
theme_name = @config.xml.diff.theme
|
|
814
814
|
return Theme[theme_name] if Theme.include?(theme_name)
|
|
815
815
|
end
|
|
@@ -826,7 +826,7 @@ _invalid_values)
|
|
|
826
826
|
return env_name if env_name && Theme.include?(env_name)
|
|
827
827
|
|
|
828
828
|
# Check config
|
|
829
|
-
if @config.
|
|
829
|
+
if @config.is_a?(Canon::Config)
|
|
830
830
|
theme_name = @config.xml.diff.theme
|
|
831
831
|
return theme_name if Theme.include?(theme_name)
|
|
832
832
|
end
|
data/lib/canon/diff_formatter.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "paint"
|
|
4
|
-
require "yaml"
|
|
3
|
+
require "paint" unless RUBY_ENGINE == "opal"
|
|
4
|
+
require "yaml" unless RUBY_ENGINE == "opal"
|
|
5
5
|
require_relative "comparison"
|
|
6
6
|
require_relative "diff/diff_block"
|
|
7
7
|
require_relative "diff/diff_context"
|
|
@@ -135,16 +135,17 @@ module Canon
|
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
# Default character visualization map (loaded from YAML)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
if RUBY_ENGINE == "opal"
|
|
139
|
+
DEFAULT_VISUALIZATION_MAP = {}.freeze
|
|
140
|
+
CHARACTER_CATEGORY_MAP = {}.freeze
|
|
141
|
+
CHARACTER_CATEGORY_NAMES = {}.freeze
|
|
142
|
+
CHARACTER_METADATA = {}.freeze
|
|
143
|
+
else
|
|
144
|
+
DEFAULT_VISUALIZATION_MAP = character_map_data[:visualization_map].freeze
|
|
145
|
+
CHARACTER_CATEGORY_MAP = character_map_data[:category_map].freeze
|
|
146
|
+
CHARACTER_CATEGORY_NAMES = character_map_data[:category_names].freeze
|
|
147
|
+
CHARACTER_METADATA = character_map_data[:character_metadata].freeze
|
|
148
|
+
end
|
|
148
149
|
|
|
149
150
|
# Map difference codes to human-readable descriptions
|
|
150
151
|
DIFF_DESCRIPTIONS = {
|
|
@@ -326,7 +327,7 @@ module Canon
|
|
|
326
327
|
return pretty_diff_formatter.format(d1, d2, format: format)
|
|
327
328
|
end
|
|
328
329
|
|
|
329
|
-
no_diffs = if differences.
|
|
330
|
+
no_diffs = if differences.is_a?(Canon::Comparison::ComparisonResult)
|
|
330
331
|
differences.equivalent?
|
|
331
332
|
else
|
|
332
333
|
differences.empty?
|
|
@@ -757,6 +758,9 @@ module Canon
|
|
|
757
758
|
output.join("\n")
|
|
758
759
|
end
|
|
759
760
|
|
|
761
|
+
public :format_line_numbered_inputs, :format_raw_inputs,
|
|
762
|
+
:format_preprocessed_inputs
|
|
763
|
+
|
|
760
764
|
# Build the final visualization map from various customization options
|
|
761
765
|
#
|
|
762
766
|
# @param visualization_map [Hash, nil] Complete custom visualization map
|
|
@@ -1,39 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "nokogiri"
|
|
3
|
+
require "nokogiri" unless RUBY_ENGINE == "opal"
|
|
4
|
+
require_relative "../xml_backend"
|
|
4
5
|
require_relative "../xml/c14n"
|
|
5
6
|
require_relative "../pretty_printer/xml"
|
|
6
7
|
require_relative "../validators/xml_validator"
|
|
7
8
|
|
|
8
9
|
module Canon
|
|
9
10
|
module Formatters
|
|
10
|
-
# XML formatter using Canonical XML 1.1 or pretty printing
|
|
11
|
-
#
|
|
12
|
-
# Use this class for formatting XML documents for display or storage.
|
|
13
|
-
# For semantic comparison of XML documents, use Canon::Comparison instead.
|
|
14
|
-
#
|
|
15
|
-
# == XML Declaration Handling
|
|
16
|
-
#
|
|
17
|
-
# - Pretty printing (default): Preserves XML declaration
|
|
18
|
-
# - Canonicalization: Removes XML declaration (per W3C C14N 1.1 spec)
|
|
19
|
-
#
|
|
20
|
-
# == Usage
|
|
21
|
-
#
|
|
22
|
-
# # Pretty print (preserves declaration)
|
|
23
|
-
# Canon.format_xml(xml)
|
|
24
|
-
#
|
|
25
|
-
# # Canonicalize (removes declaration)
|
|
26
|
-
# Canon.format(xml, :xml, pretty: false)
|
|
27
|
-
#
|
|
28
|
-
# For comparison, use:
|
|
29
|
-
# Canon::Comparison.equivalent?(xml1, xml2, format: :xml)
|
|
30
|
-
#
|
|
31
11
|
class XmlFormatter
|
|
32
|
-
# Format XML with pretty printing by default
|
|
33
|
-
# @param xml [String] XML document to format
|
|
34
|
-
# @param pretty [Boolean] Whether to pretty print (default: true)
|
|
35
|
-
# @param indent [Integer] Number of spaces for indentation (default: 2)
|
|
36
|
-
# @return [String] Formatted XML
|
|
37
12
|
def self.format(xml, pretty: true, indent: 2)
|
|
38
13
|
if pretty
|
|
39
14
|
Canon::PrettyPrinter::Xml.new(indent: indent).format(xml)
|
|
@@ -42,13 +17,13 @@ module Canon
|
|
|
42
17
|
end
|
|
43
18
|
end
|
|
44
19
|
|
|
45
|
-
# Parse XML into a Nokogiri document
|
|
46
|
-
# @param xml [String] XML document to parse
|
|
47
|
-
# @return [Nokogiri::XML::Document] Parsed XML document
|
|
48
20
|
def self.parse(xml)
|
|
49
|
-
# Validate before parsing
|
|
50
21
|
Canon::Validators::XmlValidator.validate!(xml)
|
|
51
|
-
|
|
22
|
+
if XmlBackend.nokogiri?
|
|
23
|
+
Nokogiri::XML(xml)
|
|
24
|
+
else
|
|
25
|
+
XmlParsing.parse(xml)
|
|
26
|
+
end
|
|
52
27
|
end
|
|
53
28
|
end
|
|
54
29
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "nokogiri"
|
|
3
|
+
require "nokogiri" unless RUBY_ENGINE == "opal"
|
|
4
4
|
require_relative "../data_model"
|
|
5
5
|
require_relative "../xml/nodes/root_node"
|
|
6
6
|
require_relative "../xml/nodes/element_node"
|
|
@@ -89,7 +89,7 @@ module Canon
|
|
|
89
89
|
def self.build_from_nokogiri(nokogiri_doc)
|
|
90
90
|
root = Canon::Xml::Nodes::RootNode.new
|
|
91
91
|
|
|
92
|
-
if nokogiri_doc.
|
|
92
|
+
if nokogiri_doc.is_a?(Nokogiri::XML::Document) && nokogiri_doc.root
|
|
93
93
|
# For Documents (HTML4, HTML5): process the root element
|
|
94
94
|
root.add_child(build_element_node(nokogiri_doc.root))
|
|
95
95
|
|
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "nokogiri"
|
|
3
|
+
require "nokogiri" unless RUBY_ENGINE == "opal"
|
|
4
4
|
|
|
5
5
|
module Canon
|
|
6
6
|
module PrettyPrinter
|
|
7
|
-
# Pretty printer for XML with consistent indentation
|
|
8
7
|
class Xml
|
|
9
8
|
def initialize(indent: 2, indent_type: "space")
|
|
10
9
|
@indent = indent.to_i
|
|
11
10
|
@indent_type = indent_type
|
|
12
11
|
end
|
|
13
12
|
|
|
14
|
-
# Pretty print XML with consistent indentation
|
|
15
13
|
def format(xml_string)
|
|
16
|
-
|
|
14
|
+
if Canon::XmlBackend.nokogiri?
|
|
15
|
+
nokogiri_format(xml_string)
|
|
16
|
+
else
|
|
17
|
+
moxml_format(xml_string)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def nokogiri_format(xml_string)
|
|
24
|
+
doc = Nokogiri::XML(xml_string, &:noblanks)
|
|
19
25
|
if @indent_type == "tab"
|
|
20
|
-
# For tabs, use indent_text parameter
|
|
21
26
|
doc.to_xml(indent: 1, indent_text: "\t", encoding: "UTF-8")
|
|
22
27
|
else
|
|
23
|
-
# For spaces, use indent parameter
|
|
24
28
|
doc.to_xml(indent: @indent, encoding: "UTF-8")
|
|
25
29
|
end
|
|
26
30
|
end
|
|
31
|
+
|
|
32
|
+
def moxml_format(xml_string)
|
|
33
|
+
doc = Canon::XmlParsing.parse(xml_string)
|
|
34
|
+
doc.to_xml
|
|
35
|
+
end
|
|
27
36
|
end
|
|
28
37
|
end
|
|
29
38
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "nokogiri"
|
|
3
|
+
require "nokogiri" unless RUBY_ENGINE == "opal"
|
|
4
4
|
require_relative "html_void_elements"
|
|
5
5
|
|
|
6
6
|
module Canon
|
|
@@ -154,7 +154,13 @@ module Canon
|
|
|
154
154
|
# @return [String] Serialized XML, one node per line, with content
|
|
155
155
|
# whitespace visualized at line boundaries
|
|
156
156
|
def format(xml_string)
|
|
157
|
-
doc =
|
|
157
|
+
doc = if Canon::XmlBackend.moxml?
|
|
158
|
+
Canon::XmlParsing.parse(xml_string)
|
|
159
|
+
elsif @html_mode
|
|
160
|
+
Nokogiri::HTML5(xml_string)
|
|
161
|
+
else
|
|
162
|
+
Nokogiri::XML(xml_string)
|
|
163
|
+
end
|
|
158
164
|
lines = []
|
|
159
165
|
|
|
160
166
|
if !@html_mode && doc.version
|
|
@@ -183,7 +189,7 @@ module Canon
|
|
|
183
189
|
# @return [Symbol] :strict, :normalize, or :drop
|
|
184
190
|
def classify_whitespace(element)
|
|
185
191
|
current = element
|
|
186
|
-
while current && !
|
|
192
|
+
while current && !Canon::XmlParsing.document?(current)
|
|
187
193
|
name = current.name.to_s
|
|
188
194
|
return :drop if @insens_ws.include?(name)
|
|
189
195
|
return :strict if @strict_ws.include?(name)
|
data/lib/canon/rspec_matchers.rb
CHANGED
|
@@ -177,7 +177,7 @@ module Canon
|
|
|
177
177
|
config_format = normalize_format_for_config(@format)
|
|
178
178
|
|
|
179
179
|
# Only access config if format is supported
|
|
180
|
-
if
|
|
180
|
+
if %i[xml html json yaml string].include?(config_format)
|
|
181
181
|
format_config = Canon::Config.instance.public_send(config_format)
|
|
182
182
|
if format_config.match.profile
|
|
183
183
|
opts[:global_profile] =
|
|
@@ -375,7 +375,7 @@ module Canon
|
|
|
375
375
|
diff_algorithm: diff_algorithm)
|
|
376
376
|
end
|
|
377
377
|
|
|
378
|
-
if defined?(::RSpec
|
|
378
|
+
if defined?(::RSpec.configure)
|
|
379
379
|
RSpec.configure do |config|
|
|
380
380
|
config.include(Canon::RSpecMatchers)
|
|
381
381
|
end
|
|
@@ -437,15 +437,13 @@ module Canon
|
|
|
437
437
|
|
|
438
438
|
alias to_s inspect
|
|
439
439
|
|
|
440
|
-
private
|
|
441
|
-
|
|
442
440
|
# Invalidate cached computations
|
|
443
441
|
def invalidate_cache
|
|
444
442
|
@signature = nil
|
|
445
443
|
@weight = nil
|
|
446
444
|
|
|
447
445
|
# Propagate upward
|
|
448
|
-
parent&.
|
|
446
|
+
parent&.invalidate_cache
|
|
449
447
|
end
|
|
450
448
|
end
|
|
451
449
|
end
|
|
@@ -124,6 +124,8 @@ module Canon
|
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
+
public :convert_operation
|
|
128
|
+
|
|
127
129
|
# Convert INSERT operation to DiffNode
|
|
128
130
|
#
|
|
129
131
|
# @param operation [Operation] Insert operation
|
|
@@ -153,7 +155,7 @@ module Canon
|
|
|
153
155
|
|
|
154
156
|
# Determine dimension for INSERT/DELETE operations based on node type
|
|
155
157
|
def dimension_for_insert_delete(tree_node)
|
|
156
|
-
label = tree_node.
|
|
158
|
+
label = tree_node.is_a?(Canon::TreeDiff::Core::TreeNode) ? tree_node.label : nil
|
|
157
159
|
return :comments if label == "comment"
|
|
158
160
|
|
|
159
161
|
:element_structure
|
|
@@ -359,7 +361,7 @@ module Canon
|
|
|
359
361
|
def extract_source_node(tree_node)
|
|
360
362
|
return nil if tree_node.nil?
|
|
361
363
|
|
|
362
|
-
tree_node.
|
|
364
|
+
tree_node.is_a?(Canon::TreeDiff::Core::TreeNode) ? tree_node.source_node : tree_node
|
|
363
365
|
end
|
|
364
366
|
|
|
365
367
|
# Determine if a diff is normative based on match options
|
|
@@ -383,12 +385,10 @@ module Canon
|
|
|
383
385
|
return false if node.nil?
|
|
384
386
|
|
|
385
387
|
# Get element name from node
|
|
386
|
-
element_name = if node.
|
|
387
|
-
node.label
|
|
388
|
-
elsif node.respond_to?(:name)
|
|
389
|
-
node.name # Nokogiri node
|
|
388
|
+
element_name = if node.is_a?(Canon::TreeDiff::Core::TreeNode)
|
|
389
|
+
node.label
|
|
390
390
|
else
|
|
391
|
-
|
|
391
|
+
Canon::Comparison::NodeInspector.name(node)
|
|
392
392
|
end
|
|
393
393
|
|
|
394
394
|
# Check if it's in our metadata elements list
|
|
@@ -600,6 +600,10 @@ module Canon
|
|
|
600
600
|
depth
|
|
601
601
|
end
|
|
602
602
|
|
|
603
|
+
public :normalize_text, :calculate_depth, :text_similarity,
|
|
604
|
+
:extract_text_content, :collect_all_nodes, :nodes_identical?,
|
|
605
|
+
:detect_changes
|
|
606
|
+
|
|
603
607
|
# Check if a node is in a whitespace-sensitive context
|
|
604
608
|
#
|
|
605
609
|
# HTML elements where whitespace is significant: <pre>, <code>, <textarea>, <script>, <style>
|
|
@@ -29,17 +29,14 @@ module Canon
|
|
|
29
29
|
line = nil
|
|
30
30
|
column = nil
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
if error.respond_to?(:line)
|
|
32
|
+
if error.is_a?(Nokogiri::XML::SyntaxError)
|
|
34
33
|
line = error.line
|
|
34
|
+
column = error.column
|
|
35
35
|
elsif error.message =~ /line[:\s]+(\d+)/i
|
|
36
36
|
line = ::Regexp.last_match(1).to_i
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
column = error.column
|
|
41
|
-
elsif error.message =~ /column[:\s]+(\d+)/i
|
|
42
|
-
column = ::Regexp.last_match(1).to_i
|
|
37
|
+
if error.message =~ /column[:\s]+(\d+)/i
|
|
38
|
+
column = ::Regexp.last_match(1).to_i
|
|
39
|
+
end
|
|
43
40
|
end
|
|
44
41
|
|
|
45
42
|
{ line: line, column: column }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "nokogiri"
|
|
3
|
+
require "nokogiri" unless RUBY_ENGINE == "opal"
|
|
4
4
|
require_relative "base_validator"
|
|
5
5
|
|
|
6
6
|
module Canon
|
|
@@ -94,13 +94,8 @@ module Canon
|
|
|
94
94
|
#
|
|
95
95
|
# @param error [Nokogiri::XML::SyntaxError] The syntax error
|
|
96
96
|
# @return [String, nil] Additional details about the error
|
|
97
|
-
def self.extract_details(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
details = error.errors.map(&:message).reject do |msg|
|
|
101
|
-
msg == error.message
|
|
102
|
-
end
|
|
103
|
-
details.join("; ") unless details.empty?
|
|
97
|
+
def self.extract_details(_error)
|
|
98
|
+
nil
|
|
104
99
|
end
|
|
105
100
|
|
|
106
101
|
# Build error details from multiple errors
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "nokogiri"
|
|
3
|
+
require "nokogiri" unless RUBY_ENGINE == "opal"
|
|
4
4
|
require_relative "base_validator"
|
|
5
5
|
|
|
6
6
|
module Canon
|
|
@@ -38,13 +38,8 @@ module Canon
|
|
|
38
38
|
#
|
|
39
39
|
# @param error [Nokogiri::XML::SyntaxError] The syntax error
|
|
40
40
|
# @return [String, nil] Additional details about the error
|
|
41
|
-
def self.extract_details(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
details = error.errors.map(&:message).reject do |msg|
|
|
45
|
-
msg == error.message
|
|
46
|
-
end
|
|
47
|
-
details.join("; ") unless details.empty?
|
|
41
|
+
def self.extract_details(_error)
|
|
42
|
+
nil
|
|
48
43
|
end
|
|
49
44
|
|
|
50
45
|
private_class_method :extract_details
|
data/lib/canon/version.rb
CHANGED