mechanize 2.14.2 → 2.14.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 +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/mechanize/form.rb +82 -57
- data/lib/mechanize/version.rb +1 -1
- data/lib/mechanize.rb +9 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4bea9b72a48d68e5cc8fce815e2e3b9b39ee4bed122fbf79b2caa1ebbbb1204
|
|
4
|
+
data.tar.gz: 152d668a69b5f95d3ad4a3ab8081b84804dbef39dc32986fcba0c02a6ec6c276
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 19a25078306fa1a403a02c702dd5773abab8d639f51ee06e4a24fd9113b1f896c9d85d2dad17e785acd4b14dc42c1dc1aa86af855756ff91988cceb9fa5785aa
|
|
7
|
+
data.tar.gz: 0dae28adc85617e2237d890e9a6b49448f381b8efc5977caa1f8900a15347196a0e1b6c85e06fb916b02b5df022b2411df76d948b79be06a9f0035ae51ed5521
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Mechanize CHANGELOG
|
|
2
2
|
|
|
3
|
+
## next / unreleased
|
|
4
|
+
|
|
5
|
+
## 2.14.3 / 2026-11-30
|
|
6
|
+
|
|
7
|
+
### Security and Performance
|
|
8
|
+
|
|
9
|
+
* `Mechanize::Form#build_query`, which form submission calls, no longer takes quadratic time in the number of form controls. [GHSA-wqj4-7642-gwqw](https://github.com/sparklemotion/mechanize/security/advisories/GHSA-wqj4-7642-gwqw)
|
|
10
|
+
|
|
11
|
+
### Improved
|
|
12
|
+
|
|
13
|
+
* Updated User-Agent strings to represent modern browser versions. (#679) @takatea
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
## 2.14.2 / 2026-10-26
|
|
4
17
|
|
|
5
18
|
### Security
|
data/lib/mechanize/form.rb
CHANGED
|
@@ -20,6 +20,15 @@ class Mechanize::Form
|
|
|
20
20
|
extend Forwardable
|
|
21
21
|
extend Mechanize::ElementMatcher
|
|
22
22
|
|
|
23
|
+
# Finds every control in document order, in linear time. It is one
|
|
24
|
+
# predicate on the descendant axis because a union such as "input, textarea"
|
|
25
|
+
# makes libxml2 sort the results by comparing nodes, which takes quadratic
|
|
26
|
+
# time. Matching local-name() finds what Nokogiri's CSS search finds under
|
|
27
|
+
# HTML5 and in an XHTML default namespace.
|
|
28
|
+
CONTROLS_XPATH = "./descendant::*[" \
|
|
29
|
+
"local-name()='input' or local-name()='textarea' or local-name()='select' or " \
|
|
30
|
+
"local-name()='button' or local-name()='keygen']" # :nodoc:
|
|
31
|
+
|
|
23
32
|
attr_accessor :method, :action, :name
|
|
24
33
|
|
|
25
34
|
attr_reader :fields, :buttons, :file_uploads, :radiobuttons, :checkboxes
|
|
@@ -307,7 +316,7 @@ class Mechanize::Form
|
|
|
307
316
|
|
|
308
317
|
(fields + checkboxes).reject do |f|
|
|
309
318
|
f.node["disabled"] || f.node["name"] == ""
|
|
310
|
-
end.
|
|
319
|
+
end.each do |f|
|
|
311
320
|
case f
|
|
312
321
|
when Mechanize::Form::CheckBox
|
|
313
322
|
if f.checked
|
|
@@ -344,7 +353,7 @@ class Mechanize::Form
|
|
|
344
353
|
successful_controls << b
|
|
345
354
|
}
|
|
346
355
|
|
|
347
|
-
successful_controls.
|
|
356
|
+
order_successful_controls(successful_controls).each do |ctrl|
|
|
348
357
|
qval = proc_query(ctrl)
|
|
349
358
|
query.push(*qval)
|
|
350
359
|
end
|
|
@@ -352,6 +361,16 @@ class Mechanize::Form
|
|
|
352
361
|
query
|
|
353
362
|
end
|
|
354
363
|
|
|
364
|
+
# Orders parsed controls by the position parse recorded from CONTROLS_XPATH,
|
|
365
|
+
# which is document order. Sorting them with Field#<=> would compare
|
|
366
|
+
# Nokogiri nodes, which takes at least quadratic time. Controls added after
|
|
367
|
+
# parsing go last.
|
|
368
|
+
def order_successful_controls(controls)
|
|
369
|
+
parsed, added = controls.partition { |control| @control_positions.key?(control) }
|
|
370
|
+
parsed.sort_by { |control| @control_positions[control] } + added.sort
|
|
371
|
+
end
|
|
372
|
+
private :order_successful_controls
|
|
373
|
+
|
|
355
374
|
# This method adds an index to all fields that have Hash nodes. This
|
|
356
375
|
# enables field sorting to maintain order.
|
|
357
376
|
def save_hash_field_order
|
|
@@ -582,66 +601,72 @@ class Mechanize::Form
|
|
|
582
601
|
@file_uploads = []
|
|
583
602
|
@radiobuttons = []
|
|
584
603
|
@checkboxes = []
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
when '
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
604
|
+
@control_positions = {}.compare_by_identity
|
|
605
|
+
|
|
606
|
+
# The collections list input controls before the other tags, so collect
|
|
607
|
+
# the other tags here and append them after the loop.
|
|
608
|
+
textareas = []
|
|
609
|
+
selects = []
|
|
610
|
+
keygens = []
|
|
611
|
+
button_tags = []
|
|
612
|
+
|
|
613
|
+
@node.search(CONTROLS_XPATH).each do |node|
|
|
614
|
+
case node.name
|
|
615
|
+
when 'input'
|
|
616
|
+
type = (node['type'] || 'text').downcase
|
|
617
|
+
name = node['name']
|
|
618
|
+
next if name.nil? && !%w[submit button image].include?(type)
|
|
619
|
+
case type
|
|
620
|
+
when 'radio'
|
|
621
|
+
add_control @radiobuttons, RadioButton.new(node, self)
|
|
622
|
+
when 'checkbox'
|
|
623
|
+
add_control @checkboxes, CheckBox.new(node, self)
|
|
624
|
+
when 'file'
|
|
625
|
+
add_control @file_uploads, FileUpload.new(node, nil)
|
|
626
|
+
when 'submit'
|
|
627
|
+
add_control @buttons, Submit.new(node)
|
|
628
|
+
when 'button'
|
|
629
|
+
add_control @buttons, Button.new(node)
|
|
630
|
+
when 'reset'
|
|
631
|
+
add_control @buttons, Reset.new(node)
|
|
632
|
+
when 'image'
|
|
633
|
+
add_control @buttons, ImageButton.new(node)
|
|
634
|
+
when 'hidden'
|
|
635
|
+
add_control @fields, Hidden.new(node, node['value'] || '')
|
|
636
|
+
when 'text'
|
|
637
|
+
add_control @fields, Text.new(node, node['value'] || '')
|
|
638
|
+
when 'textarea'
|
|
639
|
+
add_control @fields, Textarea.new(node, node['value'] || '')
|
|
640
|
+
else
|
|
641
|
+
add_control @fields, Field.new(node, node['value'] || '')
|
|
642
|
+
end
|
|
610
643
|
when 'textarea'
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
@fields << MultiSelectList.new(node)
|
|
628
|
-
else
|
|
629
|
-
@fields << SelectList.new(node)
|
|
644
|
+
next unless node['name']
|
|
645
|
+
add_control textareas, Textarea.new(node, node.inner_text)
|
|
646
|
+
when 'select'
|
|
647
|
+
next unless node['name']
|
|
648
|
+
if node.has_attribute? 'multiple'
|
|
649
|
+
add_control selects, MultiSelectList.new(node)
|
|
650
|
+
else
|
|
651
|
+
add_control selects, SelectList.new(node)
|
|
652
|
+
end
|
|
653
|
+
when 'button'
|
|
654
|
+
# FIXME: what can I do with the reset buttons?
|
|
655
|
+
type = (node['type'] || 'submit').downcase
|
|
656
|
+
next if type == 'reset'
|
|
657
|
+
add_control button_tags, Button.new(node)
|
|
658
|
+
when 'keygen'
|
|
659
|
+
add_control keygens, Keygen.new(node, node['value'] || '')
|
|
630
660
|
end
|
|
631
661
|
end
|
|
632
662
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
type = (node['type'] || 'submit').downcase
|
|
637
|
-
next if type == 'reset'
|
|
638
|
-
@buttons << Button.new(node)
|
|
639
|
-
end
|
|
663
|
+
@fields.concat(textareas, selects, keygens)
|
|
664
|
+
@buttons.concat(button_tags)
|
|
665
|
+
end
|
|
640
666
|
|
|
641
|
-
|
|
642
|
-
@
|
|
643
|
-
|
|
644
|
-
end
|
|
667
|
+
def add_control(list, control)
|
|
668
|
+
@control_positions[control] = @control_positions.size
|
|
669
|
+
list << control
|
|
645
670
|
end
|
|
646
671
|
|
|
647
672
|
def rand_string(len = 10)
|
data/lib/mechanize/version.rb
CHANGED
data/lib/mechanize.rb
CHANGED
|
@@ -130,18 +130,18 @@ class Mechanize
|
|
|
130
130
|
AGENT_ALIASES = {
|
|
131
131
|
'Mechanize' => "Mechanize/#{VERSION} Ruby/#{ruby_version} (http://github.com/sparklemotion/mechanize/)",
|
|
132
132
|
|
|
133
|
-
'Linux Firefox' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:
|
|
133
|
+
'Linux Firefox' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:160.0) Gecko/20100101 Firefox/160.0',
|
|
134
134
|
'Linux Konqueror' => 'Mozilla/5.0 (compatible; Konqueror/3; Linux)',
|
|
135
135
|
'Linux Mozilla' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624',
|
|
136
136
|
|
|
137
|
-
'Mac Firefox' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X
|
|
137
|
+
'Mac Firefox' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 15.8; rv:160.0) Gecko/20100101 Firefox/160.0',
|
|
138
138
|
'Mac Mozilla' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.4a) Gecko/20030401',
|
|
139
139
|
'Mac Safari 4' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-at) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10',
|
|
140
|
-
'Mac Safari' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X
|
|
140
|
+
'Mac Safari' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 15_8_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 Safari/605.1.15',
|
|
141
141
|
|
|
142
|
-
'Windows Chrome' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
143
|
-
'Windows Edge' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
144
|
-
'Windows Firefox' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:
|
|
142
|
+
'Windows Chrome' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36',
|
|
143
|
+
'Windows Edge' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36 Edg/157.0.4341.60',
|
|
144
|
+
'Windows Firefox' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:160.0) Gecko/20100101 Firefox/160.0',
|
|
145
145
|
'Windows IE 6' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
|
|
146
146
|
'Windows IE 7' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
|
|
147
147
|
'Windows IE 8' => 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
|
|
@@ -150,9 +150,9 @@ class Mechanize
|
|
|
150
150
|
'Windows IE 11' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko',
|
|
151
151
|
'Windows Mozilla' => 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6',
|
|
152
152
|
|
|
153
|
-
'Android' => 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
154
|
-
'iPad' => 'Mozilla/5.0 (iPad; CPU OS
|
|
155
|
-
'iPhone' => 'Mozilla/5.0 (iPhone; CPU iPhone OS
|
|
153
|
+
'Android' => 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.8103.80 Mobile Safari/537.36',
|
|
154
|
+
'iPad' => 'Mozilla/5.0 (iPad; CPU OS 18_7_12 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 Mobile/15E148 Safari/604.1',
|
|
155
|
+
'iPhone' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_12 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.0 Mobile/15E148 Safari/604.1',
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
AGENT_ALIASES.default_proc = proc { |hash, key|
|