Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sparklemotion/mechanize
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: socialpandas/mechanize
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Feb 19, 2013

  1. Follow meta refresh when <meta> is present and <head> is absent

    t.co responses currently aren't followed without setting agent.follow_meta_refresh = :anywhere, for example
    tombenner committed Feb 19, 2013
    Copy the full SHA
    f30844b View commit details
Showing with 16 additions and 1 deletion.
  1. +1 −1 lib/mechanize/page.rb
  2. +1 −0 test/htdocs/tc_meta_no_head.html
  3. +14 −0 test/test_mechanize.rb
2 changes: 1 addition & 1 deletion lib/mechanize/page.rb
Original file line number Diff line number Diff line change
@@ -371,7 +371,7 @@ def forms
# Return a list of all meta refresh elements

def meta_refresh
query = @mech.follow_meta_refresh == :anywhere ? 'meta' : 'head > meta'
query = @mech.follow_meta_refresh == :anywhere || search('head').empty? ? 'meta' : 'head > meta'

@meta_refresh ||= search(query).map do |node|
MetaRefresh.from_node node, self
1 change: 1 addition & 0 deletions test/htdocs/tc_meta_no_head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<noscript><meta http-equiv="refresh" content="0; url=http://localhost/index.html"></noscript><script>location.replace("http:\/\/localhost\/index.html")</script>
14 changes: 14 additions & 0 deletions test/test_mechanize.rb
Original file line number Diff line number Diff line change
@@ -492,6 +492,20 @@ def test_get_follow_meta_refresh_no_url
assert_equal('http://example/', @mech.history.last.uri.to_s)
end

def test_get_follow_meta_refresh_no_head
@mech.follow_meta_refresh = true
@mech.follow_meta_refresh_self = true

page = @mech.get('http://localhost/tc_meta_no_head.html')
assert_equal(2, @mech.history.length)
assert_equal('http://localhost/tc_meta_no_head.html',
@mech.history[0].uri.to_s)
assert_equal('http://localhost/index.html',
@mech.history[1].uri.to_s)
assert_equal('http://localhost/index.html', page.uri.to_s)
assert_equal('http://localhost/index.html', @mech.history.last.uri.to_s)
end

def test_get_follow_meta_refresh_referer_not_sent
@mech.follow_meta_refresh = true