nokogiri 1.13.0-x86_64-linux → 1.13.1-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

@@ -6,7 +6,7 @@ module Nokogiri
6
6
  #
7
7
  # The Searchable module declares the interface used for searching your DOM.
8
8
  #
9
- # It implements the public methods `search`, `css`, and `xpath`,
9
+ # It implements the public methods #search, #css, and #xpath,
10
10
  # as well as allowing specific implementations to specialize some
11
11
  # of the important behaviors.
12
12
  #
@@ -30,25 +30,22 @@ module Nokogiri
30
30
  # node.search('.//bike:tire', {'bike' => 'http://schwinn.com/'})
31
31
  # node.search('bike|tire', {'bike' => 'http://schwinn.com/'})
32
32
  #
33
- # For XPath queries, a hash of variable bindings may also be
34
- # appended to the namespace bindings. For example:
33
+ # For XPath queries, a hash of variable bindings may also be appended to the namespace
34
+ # bindings. For example:
35
35
  #
36
36
  # node.search('.//address[@domestic=$value]', nil, {:value => 'Yes'})
37
37
  #
38
- # Custom XPath functions and CSS pseudo-selectors may also be
39
- # defined. To define custom functions create a class and
40
- # implement the function you want to define. The first argument
41
- # to the method will be the current matching NodeSet. Any other
42
- # arguments are ones that you pass in. Note that this class may
43
- # appear anywhere in the argument list. For example:
44
- #
45
- # node.search('.//title[regex(., "\w+")]', 'div.employee:regex("[0-9]+")'
46
- # Class.new {
47
- # def regex node_set, regex
48
- # node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
49
- # end
50
- # }.new
51
- # )
38
+ # 💡 Custom XPath functions and CSS pseudo-selectors may also be defined. To define custom
39
+ # functions create a class and implement the function you want to define. The first argument
40
+ # to the method will be the current matching NodeSet. Any other arguments are ones that you
41
+ # pass in. Note that this class may appear anywhere in the argument list. For example:
42
+ #
43
+ # handler = Class.new {
44
+ # def regex node_set, regex
45
+ # node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
46
+ # end
47
+ # }.new
48
+ # node.search('.//title[regex(., "\w+")]', 'div.employee:regex("[0-9]+")', handler)
52
49
  #
53
50
  # See Searchable#xpath and Searchable#css for further usage help.
54
51
  def search(*args)
@@ -92,25 +89,40 @@ module Nokogiri
92
89
  #
93
90
  # node.css('bike|tire', {'bike' => 'http://schwinn.com/'})
94
91
  #
95
- # Custom CSS pseudo classes may also be defined. To define
96
- # custom pseudo classes, create a class and implement the custom
97
- # pseudo class you want defined. The first argument to the
98
- # method will be the current matching NodeSet. Any other
99
- # arguments are ones that you pass in. For example:
92
+ # 💡 Custom CSS pseudo classes may also be defined which are mapped to a custom XPath
93
+ # function. To define custom pseudo classes, create a class and implement the custom pseudo
94
+ # class you want defined. The first argument to the method will be the matching context
95
+ # NodeSet. Any other arguments are ones that you pass in. For example:
100
96
  #
101
- # node.css('title:regex("\w+")', Class.new {
102
- # def regex node_set, regex
97
+ # handler = Class.new {
98
+ # def regex(node_set, regex)
103
99
  # node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
104
100
  # end
105
- # }.new)
101
+ # }.new
102
+ # node.css('title:regex("\w+")', handler)
103
+ #
104
+ # 💡 Some XPath syntax is supported in CSS queries. For example, to query for an attribute:
106
105
  #
107
- # Note that the CSS query string is case-sensitive with regards
108
- # to your document type. That is, if you're looking for "H1" in
109
- # an HTML document, you'll never find anything, since HTML tags
110
- # will match only lowercase CSS queries. However, "H1" might be
111
- # found in an XML document, where tags names are case-sensitive
112
- # (e.g., "H1" is distinct from "h1").
106
+ # node.css('img > @href') # returns all +href+ attributes on an +img+ element
107
+ # node.css('img / @href') # same
113
108
  #
109
+ # # ⚠ this returns +class+ attributes from all +div+ elements AND THEIR CHILDREN!
110
+ # node.css('div @class')
111
+ #
112
+ # node.css
113
+ #
114
+ # 💡 Array-like syntax is supported in CSS queries as an alternative to using +:nth-child()+.
115
+ #
116
+ # ⚠ NOTE that indices are 1-based like +:nth-child+ and not 0-based like Ruby Arrays. For
117
+ # example:
118
+ #
119
+ # # equivalent to 'li:nth-child(2)'
120
+ # node.css('li[2]') # retrieve the second li element in a list
121
+ #
122
+ # ⚠ NOTE that the CSS query string is case-sensitive with regards to your document type. HTML
123
+ # tags will match only lowercase CSS queries, so if you search for "H1" in an HTML document,
124
+ # you'll never find anything. However, "H1" might be found in an XML document, where tags
125
+ # names are case-sensitive (e.g., "H1" is distinct from "h1").
114
126
  def css(*args)
115
127
  rules, handler, ns, _ = extract_params(args)
116
128
 
@@ -147,18 +159,17 @@ module Nokogiri
147
159
  #
148
160
  # node.xpath('.//address[@domestic=$value]', nil, {:value => 'Yes'})
149
161
  #
150
- # Custom XPath functions may also be defined. To define custom
151
- # functions create a class and implement the function you want
152
- # to define. The first argument to the method will be the
153
- # current matching NodeSet. Any other arguments are ones that
154
- # you pass in. Note that this class may appear anywhere in the
155
- # argument list. For example:
162
+ # 💡 Custom XPath functions may also be defined. To define custom functions create a class and
163
+ # implement the function you want to define. The first argument to the method will be the
164
+ # current matching NodeSet. Any other arguments are ones that you pass in. Note that this
165
+ # class may appear anywhere in the argument list. For example:
156
166
  #
157
- # node.xpath('.//title[regex(., "\w+")]', Class.new {
158
- # def regex node_set, regex
167
+ # handler = Class.new {
168
+ # def regex(node_set, regex)
159
169
  # node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
160
170
  # end
161
- # }.new)
171
+ # }.new
172
+ # node.xpath('.//title[regex(., "\w+")]', handler)
162
173
  #
163
174
  def xpath(*args)
164
175
  paths, handler, ns, binds = extract_params(args)
data/lib/nokogiri/xslt.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module Nokogiri
@@ -34,22 +35,28 @@ module Nokogiri
34
35
  end
35
36
  end
36
37
 
37
- ###
38
- # Quote parameters in +params+ for stylesheet safety
38
+ # :call-seq:
39
+ # quote_params(params) Array
40
+ #
41
+ # Quote parameters in +params+ for stylesheet safety.
42
+ # See Nokogiri::XSLT::Stylesheet.transform for example usage.
43
+ #
44
+ # [Parameters]
45
+ # - +params+ (Hash, Array) XSLT parameters (key->value, or tuples of [key, value])
46
+ #
47
+ # [Returns] Array of string parameters, with quotes correctly escaped for use with XSLT::Stylesheet.transform
48
+ #
39
49
  def quote_params(params)
40
- parray = (params.instance_of?(Hash) ? params.to_a.flatten : params).dup
41
- parray.each_with_index do |v, i|
42
- parray[i] = if i % 2 > 0
43
- if /'/.match?(v)
44
- "concat('#{v.gsub(/'/, %q{', "'", '})}')"
45
- else
46
- "'#{v}'"
47
- end
50
+ params.flatten.each_slice(2).each_with_object([]) do |kv, quoted_params|
51
+ key, value = kv.map(&:to_s)
52
+ value = if /'/.match?(value)
53
+ "concat('#{value.gsub(/'/, %q{', "'", '})}')"
48
54
  else
49
- v.to_s
55
+ "'#{value}'"
50
56
  end
57
+ quoted_params << key
58
+ quoted_params << value
51
59
  end
52
- parray.flatten
53
60
  end
54
61
  end
55
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 1.13.1
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Mike Dalessio
@@ -20,7 +20,7 @@ authors:
20
20
  autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
- date: 2022-01-06 00:00:00.000000000 Z
23
+ date: 2022-01-13 00:00:00.000000000 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: racc