Skip to content

🐛 Fix #194: NoMethodError on missing leading slash #211

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

Merged
merged 1 commit into from
Oct 31, 2021
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
17 changes: 8 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-10-31 19:10:34 UTC using RuboCop version 1.22.3.
# on 2021-10-31 21:29:49 UTC using RuboCop version 1.22.3.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -109,12 +109,11 @@ Layout/EmptyLineBetweenDefs:
- 'test/integration/consumer_test.rb'
- 'test/units/test_net_http_client.rb'

# Offense count: 20
# Offense count: 17
# Cop supports --auto-correct.
Layout/EmptyLines:
Exclude:
- 'lib/oauth/cli/authorize_command.rb'
- 'lib/oauth/consumer.rb'
- 'test/cases/oauth_case.rb'
- 'test/cases/spec/1_0-final/test_construct_request_url.rb'
- 'test/cases/spec/1_0-final/test_normalize_request_parameters.rb'
Expand Down Expand Up @@ -404,7 +403,7 @@ Layout/SpaceInsideBlockBraces:
- 'test/support/minitest_helpers.rb'
- 'test/units/test_consumer.rb'

# Offense count: 450
# Offense count: 452
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space, compact
Expand Down Expand Up @@ -565,14 +564,14 @@ Metrics/AbcSize:
# Offense count: 9
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 277
Max: 282

# Offense count: 7
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 18

# Offense count: 64
# Offense count: 65
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 45
Expand All @@ -585,7 +584,7 @@ Metrics/ParameterLists:
# Offense count: 7
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 17
Max: 18

# Offense count: 16
# Cop supports --auto-correct.
Expand Down Expand Up @@ -833,7 +832,7 @@ Style/CommentAnnotation:
- 'lib/oauth/tokens/request_token.rb'
- 'test/units/test_action_controller_request_proxy.rb'

# Offense count: 7
# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Expand Down Expand Up @@ -916,7 +915,7 @@ Style/HashConversion:
Exclude:
- 'lib/oauth/tokens/request_token.rb'

# Offense count: 491
# Offense count: 495
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Expand Down
20 changes: 12 additions & 8 deletions lib/oauth/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,22 @@ def proxy
# Instantiates the http object
def create_http(_url = nil)


if !request_endpoint.nil?
_url = request_endpoint
end


if _url.nil? || _url[0] =~ /^\//
our_uri = URI.parse(site)
else
our_uri = URI.parse(_url)
end

our_uri = if _url.nil? || _url[0] =~ /^\//
URI.parse(site)
else
your_uri = URI.parse(_url)
if your_uri.host.nil?
# If the _url is a path, missing the leading slash, then it won't have a host,
# and our_uri *must* have a host, so we parse site instead.
URI.parse(site)
else
your_uri
end
end

if proxy.nil?
http_object = Net::HTTP.new(our_uri.host, our_uri.port)
Expand Down