ruby_rnv 0.5.1 → 0.5.3

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: 34b0a44425bf0b95c0b8eae8671e4236099e8812c4707242e23b9cf8d8493fa6
4
- data.tar.gz: 59089293248b1dc8684584cd4e3c821805dea555f8dfdc9351451aca0ce8ba94
3
+ metadata.gz: 708b7824fc5d388ab19228ff035c2b2769a1d6847b95d3e56efe8350420ef29b
4
+ data.tar.gz: df218207c1ebfb2ca320ec3bfd03a04180b9eb5a0440676d054beb1fbcf5390d
5
5
  SHA512:
6
- metadata.gz: 35bfea201f2bd6c4243cfdc1a645fb6434b1f02c49dd6ad00cf83470a8760fb0e47c6cfeb8b113c24c4a391539cd3db07e8945bc20c5d2137065849bdab82ac2
7
- data.tar.gz: 6deaced66f1ed6cf800cabf0c09f77f61d6239ef6aa28fc1472501f33d30f6c85bbfead13aa763e6b50e3728042762a01bc04cd1eb5ed677f4856029a3cf0514
6
+ metadata.gz: 430139d49d8b6f90fab69c9d62c919b186af0cdd3aac94956fb8b57f406d87d5243fc153c058f942e568e8fc0592b41ab41df8f9b7de6da1971aeebca0b4643a
7
+ data.tar.gz: 60ca45977391df8f28cbe8c9ad2f13627a0c8379141ac4f9b084d4b1a01829b7aeb6b0d73dceda090304f694d8affb9e2d5a5f67442acc13c858bda07478467b
@@ -463,7 +463,7 @@ VALUE ruby_create_error(VALUE self, VALUE line, VALUE col, VALUE xpath, int erno
463
463
  rb_iv_set(err_obj, "@line", line); // set line from sax parser
464
464
  rb_iv_set(err_obj, "@col", col); // set col from sax parser
465
465
 
466
- rb_iv_set(err_obj, "@xpath", xpath); // set line from sax parser
466
+ rb_iv_set(err_obj, "@xpath", xpath); // set xpath from sax parser
467
467
 
468
468
  rb_iv_set(err_obj, "@required", rb_ary_new2(0));
469
469
  rb_iv_set(err_obj, "@allowed", rb_ary_new2(0));
@@ -493,7 +493,6 @@ int ruby_verror_handler(void *data, int erno, char *format, va_list ap)
493
493
  VALUE r_last_col = rb_iv_get(self, "@last_col");
494
494
  int last_line = NUM2INT(r_last_line);
495
495
  int last_col = NUM2INT(r_last_col);
496
- int xpath = NUM2INT(r_last_col);
497
496
 
498
497
  // only one error per line/col
499
498
  // if (document->last_line != last_line || document->last_col != last_col)
data/lib/rnv/error.rb CHANGED
@@ -91,6 +91,10 @@ module RNV
91
91
  "datatype #{e[-2]}:#{e.last}"
92
92
  when :rn_nc_qname
93
93
  with_ns ? "#{e.first}:#{e.last}" : e.last
94
+ when :rn_p_text
95
+ "text"
96
+ when :rn_p_after
97
+ "after"
94
98
  else
95
99
  "unknown #{e.first}"
96
100
  end
data/lib/rnv/validator.rb CHANGED
@@ -8,20 +8,52 @@ module RNV
8
8
  # @!visibility private
9
9
  class XpathNode
10
10
  attr_accessor :name
11
- attr_accessor :uri, :namespaces
11
+ attr_accessor :uri, :namespaces, :rev_namespaces, :xpath_name
12
12
  attr_accessor :parent
13
+ attr_accessor :idx
13
14
  attr_accessor :children
14
15
 
15
16
  def initialize(name)
16
17
  @name = name
18
+ @idx = 0
17
19
  @children = []
20
+ @namespaces = {}
21
+ @rev_namespaces = {}
22
+ @xpath_name = nil
18
23
  end
19
24
 
20
- def add_child(name, uri = nil, namespaces = {})
25
+ def add_child(name, uri = nil, local_namespaces = {})
21
26
  child = XpathNode.new(name)
22
27
  child.uri = uri
23
- child.namespaces = namespaces
28
+
29
+ @rev_namespaces.each do |ns_uri, ns_alias|
30
+ child.rev_namespaces[ns_uri] = ns_alias
31
+ end
32
+ local_namespaces.each do |ns_alias, ns_uri|
33
+ child.rev_namespaces[ns_uri] = ns_alias
34
+ end
35
+
36
+ all_namespaces = {}
37
+ child.rev_namespaces.each do |ns_uri, ns_alias|
38
+ all_namespaces[ns_alias] ||= []
39
+ all_namespaces[ns_alias] << ns_uri
40
+ end
41
+
42
+ child.namespaces = @namespaces.dup
24
43
  child.parent = self
44
+ child.idx = self.children.count { |other_child| other_child.name == name } + 1
45
+
46
+ if child.rev_namespaces[child.uri]
47
+ if all_namespaces[child.rev_namespaces[child.uri]].length == 1
48
+ child.namespaces[child.rev_namespaces[child.uri]] = child.uri
49
+ child.xpath_name = "#{child.rev_namespaces[child.uri]}:#{child.name}[#{child.idx}]"
50
+ else
51
+ child.xpath_name = "*[local-name() = '#{child.name}'][#{child.idx}]" # we can't say which ns it is
52
+ end
53
+ else
54
+ child.xpath_name = "xmlns:#{child.name}[#{child.idx}]"
55
+ end
56
+
25
57
  @children << child
26
58
  child
27
59
  end
@@ -29,29 +61,13 @@ module RNV
29
61
  def to_xpath
30
62
  xpath = []
31
63
  current = self
32
- namespaces = {}
33
- rev_namespaces = {}
34
- ns_current = self
35
- while ns_current.name
36
- ns_current.namespaces.each do |prefix, uri|
37
- rev_namespaces[uri] ||= []
38
- rev_namespaces[uri] << prefix
39
- end
40
- ns_current = ns_current.parent
41
- end
42
-
43
- rev_namespaces.each do |uri, prefixes|
44
- if prefixes.length > 0
45
- prefixes.select! { |prefix| prefix != "xmlns" }
46
- end
47
- namespaces[prefixes.first||"xmlns"] = uri
48
- end
49
64
 
50
65
  while current.name
51
- xpath << "#{rev_namespaces[current.uri]&.first||"xmlns"}:#{current.name}[#{current.parent.children.select { |child| child.name == current.name }.index(current) + 1}]"
66
+ xpath << current.xpath_name
52
67
  current = current.parent
53
68
  end
54
- [xpath.reverse, namespaces]
69
+
70
+ [xpath.reverse, self.namespaces]
55
71
  end
56
72
  end
57
73
 
@@ -71,20 +87,19 @@ module RNV
71
87
  tag_attrs = attrs.map { |attr| [attr.uri ? "#{attr.uri}:#{attr.localname}" : attr.localname, attr.value] }
72
88
  tag_name = uri ? "#{uri}:#{name}" : name
73
89
  namespaces = {}
74
- ns.each do |n|
90
+ ns&.each do |n|
75
91
  namespaces[n.first || "xmlns"] = n.last
76
92
  end
77
93
  @xpath_tree = @xpath_tree.add_child(name, uri, namespaces)
78
-
79
94
  update_line_col
80
95
  @document.start_tag(@pre_processor.tag(tag_name), @pre_processor.attributes(tag_attrs))
81
96
  end
82
97
 
83
98
  def end_element_namespace(name, prefix = nil, uri = nil)
84
- @xpath_tree = @xpath_tree.parent
85
99
  tag_name = uri ? "#{uri}:#{name}" : name
86
100
  update_line_col
87
101
  @document.end_tag(@pre_processor.tag(tag_name))
102
+ @xpath_tree = @xpath_tree.parent
88
103
  end
89
104
 
90
105
  def characters(value)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_rnv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Boulnois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-12 00:00:00.000000000 Z
11
+ date: 2022-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler