xcop 0.10.0 → 0.10.2

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: 20e82504b35cb8e894ef5b12fee7e8b4a1043397dab64d017c62055716235dbd
4
- data.tar.gz: 778ca1912da6fe7fdfdcf9e5a087048404a8f6a6b4b8968a4173159a460d88b4
3
+ metadata.gz: 38b6fe520c9b6d5c13c9dbb395fc5484c935311f2bfee2c83594b95023099a5a
4
+ data.tar.gz: 8484754dd75c22a9e5f21452a3a92e3704a9a1a9d37285eda11f0a0f9e11c83c
5
5
  SHA512:
6
- metadata.gz: 4095800866e282a2bfca1634eed729a30701278a2ba57bbbf8600a8c4129d269910d39e596ec6b1d2ae5492de7e3fd0d7a15f43e68e5892ed7a4ef4ae9966495
7
- data.tar.gz: 0b416653535d27f02157d7ffe7c3aeba8fb3a14ccd32f54ade5281e77fca8bc996c21b7b3acb576bfef0c1da4488bdc80502cddc0b72dd53cc35af8849238e31
6
+ metadata.gz: '0208353e4449b9b6b0a67b1cdaf324f0f0f600e00251d1dd350165b759b260bb2ffa1565427b45b6247b56421c496b8a2f927b9b980b2a9367d6cb08871d0b52'
7
+ data.tar.gz: f132099516bc9aeea73ffddc77c29f5f3a1e3e634b516da942a267e2748df87fff9a40df74d4f1af1f342e1ce7b67a074118efb07b1684e286dc01bae47f0074
data/lib/xcop/document.rb CHANGED
@@ -103,6 +103,14 @@ class Xcop::Document
103
103
  # Returns the set of namespace prefixes that are declared in +xml+
104
104
  # but never referenced by any element or attribute. A +nil+ entry in
105
105
  # the set represents the default namespace.
106
+ #
107
+ # A prefix counts as "used" not only when it appears as an element or
108
+ # attribute QName, but also when it is referenced from an attribute
109
+ # value as a +prefix:+ token. XSLT and XPath routinely mention a
110
+ # prefix only inside +select+, +test+, +match+, +as+, +use+ and
111
+ # similar attributes (e.g. +as="xs:integer"+ or +select="eo:foo()"+),
112
+ # so stripping such a "declared but not QName-used" prefix would break
113
+ # the stylesheet. See #161.
106
114
  def unused(xml)
107
115
  used = Set.new
108
116
  declared = Set.new
@@ -111,12 +119,23 @@ class Xcop::Document
111
119
  used << node.namespace.prefix if node.namespace
112
120
  node.attribute_nodes.each do |attr|
113
121
  used << attr.namespace.prefix if attr.namespace
122
+ attr.value.scan(/([A-Za-z_][\w.-]*):/) { |m| used << m.first }
114
123
  end
115
124
  node.namespace_definitions.each { |ns| declared << ns.prefix }
116
125
  end
117
126
  declared - used
118
127
  end
119
128
 
129
+ # Returns the absolute path of the local XSD schema declared by +xml+,
130
+ # or +nil+ when no schema is declared or the declared location is not a
131
+ # local file. The location comes from +xsi:noNamespaceSchemaLocation+
132
+ # or, failing that, from the second token of +xsi:schemaLocation+.
133
+ #
134
+ # A +schemaLocation+ is a URI, not a file path, so a remote schema such
135
+ # as +http://maven.apache.org/xsd/maven-4.0.0.xsd+ (the normal case for
136
+ # Maven +pom.xml+, +settings.xml+ and +site.xml+) must not be treated as
137
+ # a local file. Any location that carries a URL scheme is therefore
138
+ # skipped, leaving only truly local schemas to be validated. See #163.
120
139
  def schema(xml)
121
140
  root = xml.root
122
141
  return unless root
@@ -129,6 +148,7 @@ class Xcop::Document
129
148
  mapped.value.split.last
130
149
  end
131
150
  return unless location
151
+ return if location.match?(%r{\A[a-z][a-z0-9+.-]*://}i)
132
152
  File.expand_path(location, File.dirname(@path))
133
153
  end
134
154
 
data/lib/xcop/version.rb CHANGED
@@ -6,5 +6,5 @@
6
6
  # Copyright:: Copyright (c) 2017-2026 Yegor Bugayenko
7
7
  # License:: MIT
8
8
  module Xcop
9
- VERSION = '0.10.0'.freeze
9
+ VERSION = '0.10.2'.freeze
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko