Skip to content

Commit

Permalink
🐛 Fix #194: NoMethodError on missing leading slash
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Boling <peter.boling@gmail.com>
  • Loading branch information
pboling committed Oct 31, 2021
1 parent 16902af commit 4caf383
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
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

0 comments on commit 4caf383

Please sign in to comment.