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.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +1 -1
- data/ext/nokogiri/xslt_stylesheet.c +107 -9
- data/lib/nokogiri/css/parser.rb +351 -340
- data/lib/nokogiri/css/parser.y +241 -244
- data/lib/nokogiri/css/tokenizer.rb +2 -2
- data/lib/nokogiri/css/tokenizer.rex +1 -1
- data/lib/nokogiri/css/xpath_visitor.rb +16 -18
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/xml/searchable.rb +51 -40
- data/lib/nokogiri/xslt.rb +19 -12
- metadata +2 -2
@@ -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
|
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
|
-
#
|
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
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
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
|
96
|
-
# custom pseudo classes, create a class and implement the custom
|
97
|
-
#
|
98
|
-
#
|
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
|
-
#
|
102
|
-
# def 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
|
-
#
|
108
|
-
#
|
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.
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
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
|
-
#
|
158
|
-
# def 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
|
-
#
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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.
|
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-
|
23
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: racc
|