diff --git a/lib/mechanize.rb b/lib/mechanize.rb index 17765051..4e8d0341 100644 --- a/lib/mechanize.rb +++ b/lib/mechanize.rb @@ -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. diff --git a/lib/mechanize/cookie.rb b/lib/mechanize/cookie.rb index 2d001e80..fe7eb366 100644 --- a/lib/mechanize/cookie.rb +++ b/lib/mechanize/cookie.rb @@ -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 @@ -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 diff --git a/test/test_mechanize_http_agent.rb b/test/test_mechanize_http_agent.rb index f2fea1e7..0c327868 100644 --- a/test/test_mechanize_http_agent.rb +++ b/test/test_mechanize_http_agent.rb @@ -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 diff --git a/test/test_mechanize_page_link.rb b/test/test_mechanize_page_link.rb index 520a13c1..1be78fcf 100644 --- a/test/test_mechanize_page_link.rb +++ b/test/test_mechanize_page_link.rb @@ -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