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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88e582acc05ea06598dcdde3bd7feeaa34b865a9f14cbdb471867e011615d746
4
- data.tar.gz: 0b6ef8790866784501313c7b8485bba98bda4665ae520f6cd7fef3c24e99f9a0
3
+ metadata.gz: e4bea9b72a48d68e5cc8fce815e2e3b9b39ee4bed122fbf79b2caa1ebbbb1204
4
+ data.tar.gz: 152d668a69b5f95d3ad4a3ab8081b84804dbef39dc32986fcba0c02a6ec6c276
5
5
  SHA512:
6
- metadata.gz: 22c3ccf0b548e92b4ff08a9144156d301d80bbf93e64302db5d8efdbdeb3f54dd1f8ddd827cc09382064134ec3f4488ae8f63ac3ad0c75b5aa536046e62dd8ad
7
- data.tar.gz: 0a810214b4812af939185ccd63a73bb4adebff45afc0d94e5f931702c928e7949a21b09655dc16e36ecfd1e8e7c3d328e7c9912291373ac4d7cfb08f84ea0c5a
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
@@ -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.sort.each do |f|
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.sort.each do |ctrl| # DOM order
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
- # Find all input tags
587
- @node.search('input').each do |node|
588
- type = (node['type'] || 'text').downcase
589
- name = node['name']
590
- next if name.nil? && !%w[submit button image].include?(type)
591
- case type
592
- when 'radio'
593
- @radiobuttons << RadioButton.new(node, self)
594
- when 'checkbox'
595
- @checkboxes << CheckBox.new(node, self)
596
- when 'file'
597
- @file_uploads << FileUpload.new(node, nil)
598
- when 'submit'
599
- @buttons << Submit.new(node)
600
- when 'button'
601
- @buttons << Button.new(node)
602
- when 'reset'
603
- @buttons << Reset.new(node)
604
- when 'image'
605
- @buttons << ImageButton.new(node)
606
- when 'hidden'
607
- @fields << Hidden.new(node, node['value'] || '')
608
- when 'text'
609
- @fields << Text.new(node, node['value'] || '')
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
- @fields << Textarea.new(node, node['value'] || '')
612
- else
613
- @fields << Field.new(node, node['value'] || '')
614
- end
615
- end
616
-
617
- # Find all textarea tags
618
- @node.search('textarea').each do |node|
619
- next unless node['name']
620
- @fields << Textarea.new(node, node.inner_text)
621
- end
622
-
623
- # Find all select tags
624
- @node.search('select').each do |node|
625
- next unless node['name']
626
- if node.has_attribute? 'multiple'
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
- # Find all submit button tags
634
- # FIXME: what can I do with the reset buttons?
635
- @node.search('button').each do |node|
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
- # Find all keygen tags
642
- @node.search('keygen').each do |node|
643
- @fields << Keygen.new(node, node['value'] || '')
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)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Mechanize
3
- VERSION = "2.14.2"
3
+ VERSION = "2.14.3"
4
4
  end
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:109.0) Gecko/20100101 Firefox/121.0',
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 14.2; rv:109.0) Gecko/20100101 Firefox/121.0',
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 14_2_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15',
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/120.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/120.0.0.0 Safari/537.36 Edg/120.0.2210.133',
144
- 'Windows Firefox' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0',
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/120.0.6099.210 Mobile Safari/537.36',
154
- 'iPad' => 'Mozilla/5.0 (iPad; CPU OS 17_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1',
155
- 'iPhone' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1',
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|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mechanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.2
4
+ version: 2.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel