mechanize 2.10.0 → 2.10.1

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/{ci-test.yml → ci.yml} +4 -23
  3. data/.github/workflows/upstream.yml +51 -0
  4. data/CHANGELOG.md +5 -0
  5. data/README.md +1 -1
  6. data/Rakefile +1 -1
  7. data/lib/mechanize/cookie.rb +2 -2
  8. data/lib/mechanize/page.rb +1 -0
  9. data/lib/mechanize/version.rb +1 -1
  10. data/lib/mechanize.rb +2 -2
  11. data/test/test_mechanize.rb +2 -1
  12. data/test/test_mechanize_cookie.rb +19 -7
  13. data/test/test_mechanize_cookie_jar.rb +1 -0
  14. data/test/test_mechanize_directory_saver.rb +1 -0
  15. data/test/test_mechanize_download.rb +1 -0
  16. data/test/test_mechanize_element_not_found_error.rb +1 -0
  17. data/test/test_mechanize_file.rb +1 -0
  18. data/test/test_mechanize_file_connection.rb +2 -1
  19. data/test/test_mechanize_file_request.rb +1 -0
  20. data/test/test_mechanize_file_response.rb +1 -0
  21. data/test/test_mechanize_file_saver.rb +1 -0
  22. data/test/test_mechanize_form.rb +1 -0
  23. data/test/test_mechanize_form_check_box.rb +1 -0
  24. data/test/test_mechanize_form_encoding.rb +2 -1
  25. data/test/test_mechanize_form_field.rb +1 -0
  26. data/test/test_mechanize_form_file_upload.rb +1 -0
  27. data/test/test_mechanize_form_image_button.rb +1 -0
  28. data/test/test_mechanize_form_keygen.rb +1 -0
  29. data/test/test_mechanize_form_multi_select_list.rb +1 -0
  30. data/test/test_mechanize_form_option.rb +1 -0
  31. data/test/test_mechanize_form_radio_button.rb +1 -0
  32. data/test/test_mechanize_form_select_list.rb +1 -0
  33. data/test/test_mechanize_form_textarea.rb +1 -0
  34. data/test/test_mechanize_headers.rb +1 -0
  35. data/test/test_mechanize_history.rb +1 -0
  36. data/test/test_mechanize_http_agent.rb +5 -4
  37. data/test/test_mechanize_http_auth_challenge.rb +1 -0
  38. data/test/test_mechanize_http_auth_realm.rb +1 -0
  39. data/test/test_mechanize_http_auth_store.rb +1 -0
  40. data/test/test_mechanize_http_content_disposition_parser.rb +1 -0
  41. data/test/test_mechanize_http_www_authenticate_parser.rb +1 -0
  42. data/test/test_mechanize_image.rb +1 -0
  43. data/test/test_mechanize_link.rb +1 -0
  44. data/test/test_mechanize_page.rb +1 -0
  45. data/test/test_mechanize_page_encoding.rb +6 -5
  46. data/test/test_mechanize_page_frame.rb +1 -0
  47. data/test/test_mechanize_page_image.rb +1 -0
  48. data/test/test_mechanize_page_link.rb +14 -17
  49. data/test/test_mechanize_page_meta_refresh.rb +1 -0
  50. data/test/test_mechanize_parser.rb +1 -0
  51. data/test/test_mechanize_pluggable_parser.rb +1 -0
  52. data/test/test_mechanize_redirect_limit_reached_error.rb +1 -0
  53. data/test/test_mechanize_redirect_not_get_or_head_error.rb +1 -0
  54. data/test/test_mechanize_response_read_error.rb +1 -0
  55. data/test/test_mechanize_subclass.rb +1 -0
  56. data/test/test_mechanize_util.rb +4 -3
  57. data/test/test_mechanize_xml_file.rb +1 -0
  58. data/test/test_multi_select.rb +1 -0
  59. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dcbcae38bd4674eb12e4cc7cf33e85d97177ef6aa2d3cd975e2b899178faa54
4
- data.tar.gz: 7753407c594d4d063f061680ee0037a7605354c2c79dc767d241105500f9ced1
3
+ metadata.gz: d5d4ec84463a2df7945cede673dde4ea74d9f03270c923cd7f11d2fbc56aadcd
4
+ data.tar.gz: c5803f307bc7924da28191b6cfee4a9ce2ed4e9f5daeeee3e3cc9e38bd405cfc
5
5
  SHA512:
6
- metadata.gz: fc0c85ef0897b1ef9aff7ff29b9e158ba9d785e2e86e758542d533664c0d168f56823c9946b9243eb7eaad57e294af8fe8d7d1a5f717da15466a45d63597ee76
7
- data.tar.gz: 9f398d164b6ddc0de22301f73cf24d1d37fb68e4a7df427cad3924fac6424f35a089a0d675c6b498bfc9a28f55e1b1842c9d3356e0ac27edf5f884221b0549c3
6
+ metadata.gz: 87f463a89c2158edfce7b556e3b824a6215646c6581947c434df8e7289f2e150a986db1750d5336b9266b7aee768f4000903271472575edcb90008862071818b
7
+ data.tar.gz: 5787421c7c331be9f0adc25ae01587a88ae8c78786420113aa813a9bbddc4ea755655501add2a7afc0400c03d5f9bdfb041958c5ebc61815981c0dac084296fb
@@ -20,10 +20,10 @@ jobs:
20
20
  rubocop:
21
21
  runs-on: ubuntu-latest
22
22
  steps:
23
- - uses: actions/checkout@v3
23
+ - uses: actions/checkout@v4
24
24
  - uses: ruby/setup-ruby@v1
25
25
  with:
26
- ruby-version: "3.2"
26
+ ruby-version: "3.3"
27
27
  bundler-cache: true
28
28
  - run: bundle exec rake rubocop
29
29
 
@@ -32,31 +32,12 @@ jobs:
32
32
  strategy:
33
33
  fail-fast: false
34
34
  matrix:
35
- ruby-version: ["2.6", "2.7", "3.0", "3.1", "3.2", "3.3", "jruby-9.4", "truffleruby", "head", "jruby-head", "truffleruby-head"]
36
-
35
+ ruby-version: ["2.6", "2.7", "3.0", "3.1", "3.2", "3.3", "jruby-9.4", "truffleruby"]
37
36
  runs-on: ubuntu-latest
38
37
  steps:
39
- - uses: actions/checkout@v3
38
+ - uses: actions/checkout@v4
40
39
  - uses: ruby/setup-ruby@v1
41
40
  with:
42
41
  ruby-version: ${{matrix.ruby-version}}
43
42
  bundler-cache: true
44
- bundler: 2.3.26 # https://github.com/rubygems/rubygems/issues/6435
45
- - run: bundle exec rake test
46
-
47
- test-platform:
48
- needs: ["rubocop"]
49
- strategy:
50
- fail-fast: false
51
- matrix:
52
- platform: ["windows-latest", "macos-latest"]
53
-
54
- runs-on: ${{matrix.platform}}
55
- steps:
56
- - uses: actions/checkout@v3
57
- - uses: ruby/setup-ruby@v1
58
- with:
59
- ruby-version: "3.2"
60
- bundler-cache: true
61
- bundler: latest
62
43
  - run: bundle exec rake test
@@ -0,0 +1,51 @@
1
+ name: "upstream"
2
+
3
+ concurrency:
4
+ group: "${{github.workflow}}-${{github.ref}}"
5
+ cancel-in-progress: true
6
+
7
+ on:
8
+ workflow_dispatch:
9
+ schedule:
10
+ - cron: "0 8 * * 5" # At 08:00 on Friday # https://crontab.guru/#0_8_*_*_5
11
+ push:
12
+ branches:
13
+ - main
14
+ pull_request:
15
+ types: [opened, synchronize]
16
+ branches:
17
+ - main
18
+ paths:
19
+ - .github/workflows/upstream.yml # this file
20
+
21
+ jobs:
22
+ test:
23
+ strategy:
24
+ fail-fast: false
25
+ matrix:
26
+ ruby-version: ["head", "jruby-head", "truffleruby-head"]
27
+ runs-on: ubuntu-latest
28
+ steps:
29
+ - uses: actions/checkout@v4
30
+ - uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{matrix.ruby-version}}
33
+ bundler-cache: true
34
+ - run: bundle exec rake test
35
+
36
+ upstream:
37
+ name: "upstream (${{matrix.name}})"
38
+ strategy:
39
+ fail-fast: false
40
+ matrix:
41
+ include:
42
+ - { name: "nokogiri", git: "https://github.com/sparklemotion/nokogiri" }
43
+ runs-on: ubuntu-latest
44
+ steps:
45
+ - uses: actions/checkout@v4
46
+ - uses: ruby/setup-ruby@v1
47
+ with: { ruby-version: "3.3" }
48
+ - run: |
49
+ bundle add ${{matrix.name}} --git="${{matrix.git}}"
50
+ bundle show
51
+ - run: bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Mechanize CHANGELOG
2
2
 
3
+ ## 2.10.1 / 2024-06-12
4
+
5
+ * Improve page encoding error recovery on pages with broken encoding when used with libxml2 >= 2.12.0. (#644) @flavorjones
6
+
7
+
3
8
  ## 2.10.0 / 2024-01-22
4
9
 
5
10
  * Add `nkf` and `base64` as explicit dependencies, since they are being unbundled in Ruby 3.4. (#634) @flavorjones
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  * https://www.rubydoc.info/gems/mechanize/
4
4
  * https://github.com/sparklemotion/mechanize
5
5
 
6
- [![Test suite](https://github.com/sparklemotion/mechanize/actions/workflows/ci-test.yml/badge.svg)](https://github.com/sparklemotion/mechanize/actions/workflows/ci-test.yml)
6
+ [![Test suite](https://github.com/sparklemotion/mechanize/actions/workflows/ci.yml/badge.svg)](https://github.com/sparklemotion/mechanize/actions/workflows/ci.yml)
7
7
 
8
8
 
9
9
  ## Description
data/Rakefile CHANGED
@@ -49,7 +49,7 @@ namespace "rubocop" do
49
49
 
50
50
  desc "Run rubocop string literals check"
51
51
  task :frozen_string_literals do
52
- sh "rubocop lib --auto-correct-all --only Style/FrozenStringLiteralComment"
52
+ sh "rubocop lib test --auto-correct-all --only Style/FrozenStringLiteralComment"
53
53
  end
54
54
  end
55
55
 
@@ -7,7 +7,7 @@ class Mechanize
7
7
  module CookieDeprecated
8
8
  def __deprecated__(to = nil)
9
9
  $VERBOSE or return
10
- method = caller[0][/([^`]+)(?='$)/]
10
+ method = caller_locations(1,1).first.base_label
11
11
  to ||= method
12
12
  case self
13
13
  when Class
@@ -21,7 +21,7 @@ class Mechanize
21
21
  this = '%s#%s' % [klass, method]
22
22
  that = 'HTTP::%s#%s' % [lname, to]
23
23
  end
24
- warn '%s: The call of %s needs to be fixed to follow the new API (%s).' % [caller[1], this, that]
24
+ warn '%s: The call of %s needs to be fixed to follow the new API (%s).' % [caller_locations(2,1).first, this, that]
25
25
  end
26
26
  private :__deprecated__
27
27
  end
@@ -101,6 +101,7 @@ class Mechanize::Page < Mechanize::File
101
101
  return false if parser.errors.empty?
102
102
  parser.errors.any? do |error|
103
103
  error.message.scrub =~ /(indicate\ encoding)|
104
+ (Invalid\ bytes)|
104
105
  (Invalid\ char)|
105
106
  (input\ conversion\ failed)/x
106
107
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Mechanize
3
- VERSION = "2.10.0"
3
+ VERSION = "2.10.1"
4
4
  end
data/lib/mechanize.rb CHANGED
@@ -717,10 +717,10 @@ class Mechanize
717
717
  # authentication.
718
718
 
719
719
  def auth user, password, domain = nil
720
- caller.first =~ /(.*?):(\d+).*?$/
720
+ c = caller_locations(1,1).first
721
721
 
722
722
  warn <<-WARNING
723
- At #{$1} line #{$2}
723
+ At #{c.absolute_path} line #{c.lineno}
724
724
 
725
725
  Use of #auth and #basic_auth are deprecated due to a security vulnerability.
726
726
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'mechanize/test_case'
4
5
 
@@ -965,7 +966,7 @@ but not <a href="/" rel="me nofollow">this</a>!
965
966
  })
966
967
 
967
968
  assert_match(
968
- "Content-Disposition: form-data; name=\"userfile1\"; filename=\"#{name}\"".force_encoding(Encoding::ASCII_8BIT),
969
+ "Content-Disposition: form-data; name=\"userfile1\"; filename=\"#{name}\"".dup.force_encoding(Encoding::ASCII_8BIT),
969
970
  page.body
970
971
  )
971
972
  assert_match("Content-Type: application/zip", page.body)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  module Enumerable
@@ -301,7 +302,7 @@ class TestMechanizeCookie < Mechanize::TestCase
301
302
  expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
302
303
 
303
304
  cookie_params.keys.combine.each do |c|
304
- cookie_text = "#{cookie_value}; "
305
+ cookie_text = +"#{cookie_value}; "
305
306
  c.each_with_index do |key, idx|
306
307
  if idx == (c.length - 1)
307
308
  cookie_text << "#{cookie_params[key]}"
@@ -336,7 +337,7 @@ class TestMechanizeCookie < Mechanize::TestCase
336
337
  expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
337
338
 
338
339
  cookie_params.keys.combine.each do |c|
339
- cookie_text = "#{cookie_value}; "
340
+ cookie_text = +"#{cookie_value}; "
340
341
  c.each_with_index do |key, idx|
341
342
  if idx == (c.length - 1)
342
343
  cookie_text << "#{cookie_params[key]}"
@@ -373,7 +374,7 @@ class TestMechanizeCookie < Mechanize::TestCase
373
374
 
374
375
  cookie_params.keys.combine.each do |c|
375
376
  next if c.find { |k| k == 'path' }
376
- cookie_text = "#{cookie_value}; "
377
+ cookie_text = +"#{cookie_value}; "
377
378
  c.each_with_index do |key, idx|
378
379
  if idx == (c.length - 1)
379
380
  cookie_text << "#{cookie_params[key]}"
@@ -410,7 +411,7 @@ class TestMechanizeCookie < Mechanize::TestCase
410
411
 
411
412
  cookie_params.keys.combine.each do |c|
412
413
  next unless c.find { |k| k == 'secure' }
413
- cookie_text = "#{cookie_value}; "
414
+ cookie_text = +"#{cookie_value}; "
414
415
  c.each_with_index do |key, idx|
415
416
  if idx == (c.length - 1)
416
417
  cookie_text << "#{cookie_params[key]}"
@@ -446,7 +447,7 @@ class TestMechanizeCookie < Mechanize::TestCase
446
447
  expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
447
448
 
448
449
  cookie_params.keys.combine.each do |c|
449
- cookie_text = "#{cookie_value};"
450
+ cookie_text = +"#{cookie_value};"
450
451
  c.each_with_index do |key, idx|
451
452
  if idx == (c.length - 1)
452
453
  cookie_text << "#{cookie_params[key]}"
@@ -502,12 +503,23 @@ class TestMechanizeCookie < Mechanize::TestCase
502
503
  cookie.domain = 'Dom.example.com'
503
504
  assert 'dom.example.com', cookie.domain
504
505
 
505
- cookie.domain = Object.new.tap { |o|
506
+ new_domain = Object.new.tap { |o|
506
507
  def o.to_str
507
508
  'Example.com'
508
509
  end
509
510
  }
511
+ cookie.domain = new_domain
510
512
  assert 'example.com', cookie.domain
513
+
514
+ new_domain = Object.new.tap { |o|
515
+ def o.to_str
516
+ 'Example2.com'
517
+ end
518
+ }
519
+ assert_output nil, /The call of Mechanize::Cookie#set_domain/ do
520
+ cookie.set_domain(new_domain)
521
+ end
522
+ assert 'example2.com', cookie.domain
511
523
  end
512
524
 
513
525
  def test_cookie_httponly
@@ -519,7 +531,7 @@ class TestMechanizeCookie < Mechanize::TestCase
519
531
  expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
520
532
 
521
533
  cookie_params.keys.combine.each do |c|
522
- cookie_text = "#{cookie_value}; "
534
+ cookie_text = +"#{cookie_value}; "
523
535
  c.each_with_index do |key, idx|
524
536
  if idx == (c.length - 1)
525
537
  cookie_text << "#{cookie_params[key]}"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
  require 'fileutils'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeDirectorySaver < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeDownload < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeRedirectLimitReachedError < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFile < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFileConnection < Mechanize::TestCase
@@ -7,7 +8,7 @@ class TestMechanizeFileConnection < Mechanize::TestCase
7
8
  uri = URI.parse "file://#{file_path}"
8
9
  conn = Mechanize::FileConnection.new
9
10
 
10
- body = ''
11
+ body = +''
11
12
 
12
13
  conn.request uri, nil do |response|
13
14
  assert_equal(file_path, response.file_path)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFileRequest < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFileResponse < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFileSaver < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeForm < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormCheckBox < Mechanize::TestCase
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'mechanize/test_case'
3
4
 
4
5
  class TestMechanizeFormEncoding < Mechanize::TestCase
@@ -8,7 +9,7 @@ class TestMechanizeFormEncoding < Mechanize::TestCase
8
9
 
9
10
  INPUTTED_VALUE = "テスト" # "test" in Japanese UTF-8 encoding
10
11
  CONTENT_ENCODING = 'Shift_JIS' # one of Japanese encoding
11
- encoded_value = "\x83\x65\x83\x58\x83\x67".force_encoding(::Encoding::SHIFT_JIS) # "test" in Japanese Shift_JIS encoding
12
+ encoded_value = "\x83\x65\x83\x58\x83\x67".dup.force_encoding(::Encoding::SHIFT_JIS) # "test" in Japanese Shift_JIS encoding
12
13
  EXPECTED_QUERY = "first_name=#{CGI.escape(encoded_value)}&first_name=&gender=&green%5Beggs%5D="
13
14
 
14
15
  ENCODING_ERRORS = [EncodingError, Encoding::ConverterNotFoundError] # and so on
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormField < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormFileUpload < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormImageButton < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormKeygen < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormMultiSelectList < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormOption < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormRadioButton < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormSelectList < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeFormTextarea < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeHeaders < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeHistory < Mechanize::TestCase
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'mechanize/test_case'
4
5
 
@@ -29,7 +30,7 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
29
30
 
30
31
  def skip_if_jruby_zlib
31
32
  if RUBY_ENGINE == 'jruby'
32
- meth = caller[0][/`(\w+)/, 1]
33
+ meth = caller_locations(1,1).first.base_label
33
34
  skip "#{meth}: skipped because how Zlib handles error is different in JRuby"
34
35
  end
35
36
  end
@@ -1027,7 +1028,7 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
1027
1028
 
1028
1029
  body = @agent.response_content_encoding @res, body_io
1029
1030
 
1030
- expected = "test\xB2"
1031
+ expected = +"test\xB2"
1031
1032
  expected.force_encoding Encoding::BINARY if have_encoding?
1032
1033
 
1033
1034
  content = body.read
@@ -1432,11 +1433,11 @@ class TestMechanizeHttpAgent < Mechanize::TestCase
1432
1433
 
1433
1434
  io = @agent.response_read res, req, uri
1434
1435
 
1435
- expected = "π\n".force_encoding(Encoding::BINARY)
1436
+ expected = "π\n".dup.force_encoding(Encoding::BINARY)
1436
1437
 
1437
1438
  # Ruby 1.8.7 doesn't let us set the write mode of the tempfile to binary,
1438
1439
  # so we should expect an inserted carriage return on some platforms
1439
- expected_with_carriage_return = "π\r\n".force_encoding(Encoding::BINARY)
1440
+ expected_with_carriage_return = "π\r\n".dup.force_encoding(Encoding::BINARY)
1440
1441
 
1441
1442
  body = io.read
1442
1443
  assert_match(/^(#{expected}|#{expected_with_carriage_return})$/m, body)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeHttpAuthChallenge < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeHttpAuthRealm < Mechanize::TestCase
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'mechanize/test_case'
4
5
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeHttpContentDispositionParser < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeHttpWwwAuthenticateParser < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeImage < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeLink < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizePage < Mechanize::TestCase
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
  require 'mechanize/test_case'
3
4
 
4
5
  # tests for Page encoding and charset and parsing
@@ -12,7 +13,7 @@ class TestMechanizePageEncoding < Mechanize::TestCase
12
13
 
13
14
  @uri = URI('http://localhost/')
14
15
  @response_headers = { 'content-type' => 'text/html' }
15
- @body = '<title>hi</title>'
16
+ @body = +'<title>hi</title>'
16
17
  end
17
18
 
18
19
  def util_page body = @body, headers = @response_headers
@@ -118,7 +119,7 @@ class TestMechanizePageEncoding < Mechanize::TestCase
118
119
  end
119
120
 
120
121
  def test_meta_charset
121
- body = '<meta http-equiv="content-type" content="text/html;charset=META">'
122
+ body = +'<meta http-equiv="content-type" content="text/html;charset=META">'
122
123
  page = util_page body
123
124
 
124
125
  assert_equal ['META'], page.meta_charset
@@ -132,7 +133,7 @@ class TestMechanizePageEncoding < Mechanize::TestCase
132
133
 
133
134
  def test_encodings
134
135
  response = {'content-type' => 'text/html;charset=HEADER'}
135
- body = '<meta http-equiv="content-type" content="text/html;charset=META">'
136
+ body = +'<meta http-equiv="content-type" content="text/html;charset=META">'
136
137
  @mech.default_encoding = 'DEFAULT'
137
138
  page = util_page body, response
138
139
 
@@ -175,7 +176,7 @@ class TestMechanizePageEncoding < Mechanize::TestCase
175
176
  def test_parser_encoding_when_searching_elements
176
177
  skip "Encoding not implemented" unless have_encoding?
177
178
 
178
- body = '<span id="latin1">hi</span>'
179
+ body = +'<span id="latin1">hi</span>'
179
180
  page = util_page body, 'content-type' => 'text/html,charset=ISO-8859-1'
180
181
 
181
182
  result = page.search('#latin1')
@@ -187,7 +188,7 @@ class TestMechanizePageEncoding < Mechanize::TestCase
187
188
  skip if RUBY_ENGINE == 'jruby' # this is a libxml2-specific condition
188
189
 
189
190
  # https://github.com/sparklemotion/mechanize/issues/553
190
- body = <<~EOF
191
+ body = +<<~EOF
191
192
  <html>
192
193
  <body>
193
194
  <!--
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizePageFrame < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizePageImage < Mechanize::TestCase
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'mechanize/test_case'
4
5
 
@@ -11,7 +12,7 @@ class TestMechanizePageLink < Mechanize::TestCase
11
12
  <title>hi</title>
12
13
  HTML
13
14
 
14
- BAD = <<-HTML
15
+ BAD = <<-HTML.dup
15
16
  <meta http-equiv="content-type" content="text/html; charset=windows-1255">
16
17
  <title>Bia\xB3ystok</title>
17
18
  HTML
@@ -19,18 +20,16 @@ class TestMechanizePageLink < Mechanize::TestCase
19
20
 
20
21
  SJIS_TITLE = "\x83\x65\x83\x58\x83\x67"
21
22
 
22
- SJIS_AFTER_TITLE = <<-HTML
23
+ SJIS_AFTER_TITLE = <<-HTML.dup
23
24
  <title>#{SJIS_TITLE}</title>
24
25
  <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
25
26
  HTML
26
-
27
27
  SJIS_AFTER_TITLE.force_encoding Encoding::BINARY if defined? Encoding
28
28
 
29
- SJIS_BAD_AFTER_TITLE = <<-HTML
29
+ SJIS_BAD_AFTER_TITLE = <<-HTML.dup
30
30
  <title>#{SJIS_TITLE}</title>
31
31
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
32
32
  HTML
33
-
34
33
  SJIS_BAD_AFTER_TITLE.force_encoding Encoding::BINARY if defined? Encoding
35
34
 
36
35
  UTF8_TITLE = 'テスト'
@@ -46,7 +45,7 @@ class TestMechanizePageLink < Mechanize::TestCase
46
45
 
47
46
  @uri = URI('http://example')
48
47
  @res = { 'content-type' => 'text/html' }
49
- @body = '<title>hi</title>'
48
+ @body = +'<title>hi</title>'
50
49
  end
51
50
 
52
51
  def util_page body = @body, res = @res
@@ -55,7 +54,7 @@ class TestMechanizePageLink < Mechanize::TestCase
55
54
 
56
55
  def skip_if_nkf_dependency
57
56
  if RUBY_ENGINE == 'jruby'
58
- meth = caller[0][/`(\w+)/, 1]
57
+ meth = caller_locations(1,1).first.base_label
59
58
  skip "#{meth}: skipped because this feature currently depends on NKF"
60
59
  end
61
60
  end
@@ -75,7 +74,7 @@ class TestMechanizePageLink < Mechanize::TestCase
75
74
  end
76
75
 
77
76
  def test_canonical_uri_unescaped
78
- page = util_page <<-BODY
77
+ page = util_page(+<<-BODY)
79
78
  <head>
80
79
  <link rel="canonical" href="http://example/white space"/>
81
80
  </head>
@@ -97,7 +96,7 @@ class TestMechanizePageLink < Mechanize::TestCase
97
96
  end
98
97
 
99
98
  def test_encoding
100
- page = util_page WINDOWS_1255
99
+ page = util_page WINDOWS_1255.dup
101
100
 
102
101
  assert_equal 'windows-1255', page.encoding
103
102
  end
@@ -115,13 +114,12 @@ class TestMechanizePageLink < Mechanize::TestCase
115
114
 
116
115
  # https://gitlab.gnome.org/GNOME/libxml2/-/issues/543
117
116
  skip if Nokogiri.uses_libxml?([">= 2.11.0", "< 2.12.0"])
118
- expected_encoding = Nokogiri.uses_libxml?("< 2.11.0") ? 'UTF-8' : 'Shift_JIS'
119
117
 
120
- page = util_page UTF8
118
+ page = util_page UTF8.dup
121
119
 
122
120
  assert_equal false, page.encoding_error?
123
121
 
124
- assert_equal expected_encoding, page.encoding
122
+ assert_equal "UTF-8", page.encoding
125
123
  end
126
124
 
127
125
  def test_encoding_charset_after_title_double_bad
@@ -139,9 +137,8 @@ class TestMechanizePageLink < Mechanize::TestCase
139
137
 
140
138
  # https://gitlab.gnome.org/GNOME/libxml2/-/issues/543
141
139
  skip if Nokogiri.uses_libxml?([">= 2.11.0", "< 2.12.0"])
142
- expected_encoding = Nokogiri.uses_libxml?("< 2.11.0") ? 'UTF-8' : 'Shift_JIS'
143
140
 
144
- page = util_page "<title>#{UTF8_TITLE}</title>"
141
+ page = util_page(+"<title>#{UTF8_TITLE}</title>")
145
142
  page.encodings.replace %w[
146
143
  UTF-8
147
144
  Shift_JIS
@@ -149,11 +146,11 @@ class TestMechanizePageLink < Mechanize::TestCase
149
146
 
150
147
  assert_equal false, page.encoding_error?
151
148
 
152
- assert_equal expected_encoding, page.encoding
149
+ assert_equal 'UTF-8', page.encoding
153
150
  end
154
151
 
155
152
  def test_encoding_meta_charset
156
- page = util_page "<meta charset='UTF-8'>"
153
+ page = util_page(+"<meta charset='UTF-8'>")
157
154
 
158
155
  assert_equal 'UTF-8', page.encoding
159
156
  end
@@ -344,7 +341,7 @@ class TestMechanizePageLink < Mechanize::TestCase
344
341
  end
345
342
 
346
343
  def test_title_none
347
- page = util_page '' # invalid HTML
344
+ page = util_page(+'') # invalid HTML
348
345
 
349
346
  assert_nil(page.title)
350
347
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizePageMetaRefresh < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeParser < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizePluggableParser < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeRedirectLimitReachedError < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeRedirectNotGetOrHead < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeResponseReadError < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeSubclass < Mechanize::TestCase
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'mechanize/test_case'
4
5
 
@@ -6,7 +7,7 @@ class TestMechanizeUtil < Mechanize::TestCase
6
7
 
7
8
  INPUTTED_VALUE = "テスト" # "test" in Japanese UTF-8 encoding
8
9
  CONTENT_ENCODING = 'Shift_JIS' # one of Japanese encoding
9
- ENCODED_VALUE = "\x83\x65\x83\x58\x83\x67".force_encoding(::Encoding::SHIFT_JIS) # "test" in Japanese Shift_JIS encoding
10
+ ENCODED_VALUE = "\x83\x65\x83\x58\x83\x67".dup.force_encoding(::Encoding::SHIFT_JIS) # "test" in Japanese Shift_JIS encoding
10
11
 
11
12
  ENCODING_ERRORS = [EncodingError, Encoding::ConverterNotFoundError] # and so on
12
13
  ERROR_LOG_MESSAGE = /from_native_charset: Encoding::ConverterNotFoundError: form encoding: "UTF-eight"/
@@ -67,7 +68,7 @@ class TestMechanizeUtil < Mechanize::TestCase
67
68
  end
68
69
 
69
70
  def test_from_native_charset_logs_form_when_encoding_error_raised
70
- sio = StringIO.new("")
71
+ sio = StringIO.new
71
72
  log = Logger.new(sio)
72
73
  log.level = Logger::DEBUG
73
74
 
@@ -79,7 +80,7 @@ class TestMechanizeUtil < Mechanize::TestCase
79
80
  end
80
81
 
81
82
  def test_from_native_charset_logs_form_when_encoding_error_is_ignored
82
- sio = StringIO.new("")
83
+ sio = StringIO.new
83
84
  log = Logger.new(sio)
84
85
  log.level = Logger::DEBUG
85
86
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class TestMechanizeXmlFile < Mechanize::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mechanize/test_case'
2
3
 
3
4
  class MultiSelectTest < Mechanize::TestCase
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.10.0
4
+ version: 2.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -9,10 +9,10 @@ authors:
9
9
  - Mike Dalessio
10
10
  - Akinori MUSHA
11
11
  - Lee Jarvis
12
- autorequire:
12
+ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2024-01-22 00:00:00.000000000 Z
15
+ date: 2024-06-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: addressable
@@ -296,7 +296,8 @@ extra_rdoc_files:
296
296
  files:
297
297
  - ".autotest"
298
298
  - ".github/dependabot.yml"
299
- - ".github/workflows/ci-test.yml"
299
+ - ".github/workflows/ci.yml"
300
+ - ".github/workflows/upstream.yml"
300
301
  - ".gitignore"
301
302
  - ".yardopts"
302
303
  - CHANGELOG.md
@@ -514,7 +515,7 @@ metadata:
514
515
  documentation_uri: https://www.rubydoc.info/gems/mechanize
515
516
  homepage_uri: https://github.com/sparklemotion/mechanize
516
517
  source_code_uri: https://github.com/sparklemotion/mechanize
517
- post_install_message:
518
+ post_install_message:
518
519
  rdoc_options:
519
520
  - "--main"
520
521
  - README.md
@@ -531,8 +532,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
531
532
  - !ruby/object:Gem::Version
532
533
  version: '0'
533
534
  requirements: []
534
- rubygems_version: 3.5.5
535
- signing_key:
535
+ rubygems_version: 3.5.11
536
+ signing_key:
536
537
  specification_version: 4
537
538
  summary: The Mechanize library is used for automating interaction with websites
538
539
  test_files: