Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer caller_locations and Thread::Backtrace::Location methods to Kernel#caller #638

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/mechanize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,10 @@ class << self
# authentication.

def auth user, password, domain = nil
caller.first =~ /(.*?):(\d+).*?$/
c = caller_locations(1,1).first

warn <<-WARNING
At #{$1} line #{$2}
At #{c.absolute_path} line #{c.lineno}

Use of #auth and #basic_auth are deprecated due to a security vulnerability.

Expand Down
4 changes: 2 additions & 2 deletions lib/mechanize/cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Mechanize
module CookieDeprecated
def __deprecated__(to = nil)
$VERBOSE or return
method = caller[0][/([^`]+)(?='$)/]
method = caller_locations(1,1).first.base_label
to ||= method
case self
when Class
Expand All @@ -21,7 +21,7 @@ def __deprecated__(to = nil)
this = '%s#%s' % [klass, method]
that = 'HTTP::%s#%s' % [lname, to]
end
warn '%s: The call of %s needs to be fixed to follow the new API (%s).' % [caller[1], this, that]
warn '%s: The call of %s needs to be fixed to follow the new API (%s).' % [caller_locations(2,1).first, this, that]
end
private :__deprecated__
end
Expand Down
13 changes: 12 additions & 1 deletion test/test_mechanize_cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,23 @@ def test_domain=
cookie.domain = 'Dom.example.com'
assert 'dom.example.com', cookie.domain

cookie.domain = Object.new.tap { |o|
new_domain = Object.new.tap { |o|
def o.to_str
'Example.com'
end
}
cookie.domain = new_domain
assert 'example.com', cookie.domain

new_domain = Object.new.tap { |o|
def o.to_str
'Example2.com'
end
}
assert_output nil, /The call of Mechanize::Cookie#set_domain/ do
cookie.set_domain(new_domain)
end
assert 'example2.com', cookie.domain
end

def test_cookie_httponly
Expand Down
2 changes: 1 addition & 1 deletion test/test_mechanize_http_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def auth_realm uri, scheme, type

def skip_if_jruby_zlib
if RUBY_ENGINE == 'jruby'
meth = caller[0][/`(\w+)/, 1]
meth = caller_locations(1,1).first.base_label
skip "#{meth}: skipped because how Zlib handles error is different in JRuby"
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_mechanize_page_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def util_page body = @body, res = @res

def skip_if_nkf_dependency
if RUBY_ENGINE == 'jruby'
meth = caller[0][/`(\w+)/, 1]
meth = caller_locations(1,1).first.base_label
skip "#{meth}: skipped because this feature currently depends on NKF"
end
end
Expand Down
Loading