Skip to content

Commit 6af33e4

Browse files
authored
🔀 Merge pull request #211 from oauth-xx/issue/194-missing-leading-slash-error
🐛 Fix #194: NoMethodError on missing leading slash
2 parents 16902af + 4caf383 commit 6af33e4

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

.rubocop_todo.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2021-10-31 19:10:34 UTC using RuboCop version 1.22.3.
3+
# on 2021-10-31 21:29:49 UTC using RuboCop version 1.22.3.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -109,12 +109,11 @@ Layout/EmptyLineBetweenDefs:
109109
- 'test/integration/consumer_test.rb'
110110
- 'test/units/test_net_http_client.rb'
111111

112-
# Offense count: 20
112+
# Offense count: 17
113113
# Cop supports --auto-correct.
114114
Layout/EmptyLines:
115115
Exclude:
116116
- 'lib/oauth/cli/authorize_command.rb'
117-
- 'lib/oauth/consumer.rb'
118117
- 'test/cases/oauth_case.rb'
119118
- 'test/cases/spec/1_0-final/test_construct_request_url.rb'
120119
- 'test/cases/spec/1_0-final/test_normalize_request_parameters.rb'
@@ -404,7 +403,7 @@ Layout/SpaceInsideBlockBraces:
404403
- 'test/support/minitest_helpers.rb'
405404
- 'test/units/test_consumer.rb'
406405

407-
# Offense count: 450
406+
# Offense count: 452
408407
# Cop supports --auto-correct.
409408
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
410409
# SupportedStyles: space, no_space, compact
@@ -565,14 +564,14 @@ Metrics/AbcSize:
565564
# Offense count: 9
566565
# Configuration parameters: CountComments, CountAsOne.
567566
Metrics/ClassLength:
568-
Max: 277
567+
Max: 282
569568

570569
# Offense count: 7
571570
# Configuration parameters: IgnoredMethods.
572571
Metrics/CyclomaticComplexity:
573572
Max: 18
574573

575-
# Offense count: 64
574+
# Offense count: 65
576575
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
577576
Metrics/MethodLength:
578577
Max: 45
@@ -585,7 +584,7 @@ Metrics/ParameterLists:
585584
# Offense count: 7
586585
# Configuration parameters: IgnoredMethods.
587586
Metrics/PerceivedComplexity:
588-
Max: 17
587+
Max: 18
589588

590589
# Offense count: 16
591590
# Cop supports --auto-correct.
@@ -833,7 +832,7 @@ Style/CommentAnnotation:
833832
- 'lib/oauth/tokens/request_token.rb'
834833
- 'test/units/test_action_controller_request_proxy.rb'
835834

836-
# Offense count: 7
835+
# Offense count: 6
837836
# Cop supports --auto-correct.
838837
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
839838
# SupportedStyles: assign_to_condition, assign_inside_condition
@@ -916,7 +915,7 @@ Style/HashConversion:
916915
Exclude:
917916
- 'lib/oauth/tokens/request_token.rb'
918917

919-
# Offense count: 491
918+
# Offense count: 495
920919
# Cop supports --auto-correct.
921920
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
922921
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys

lib/oauth/consumer.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,22 @@ def proxy
343343
# Instantiates the http object
344344
def create_http(_url = nil)
345345

346-
347346
if !request_endpoint.nil?
348347
_url = request_endpoint
349348
end
350349

351-
352-
if _url.nil? || _url[0] =~ /^\//
353-
our_uri = URI.parse(site)
354-
else
355-
our_uri = URI.parse(_url)
356-
end
357-
350+
our_uri = if _url.nil? || _url[0] =~ /^\//
351+
URI.parse(site)
352+
else
353+
your_uri = URI.parse(_url)
354+
if your_uri.host.nil?
355+
# If the _url is a path, missing the leading slash, then it won't have a host,
356+
# and our_uri *must* have a host, so we parse site instead.
357+
URI.parse(site)
358+
else
359+
your_uri
360+
end
361+
end
358362

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

0 commit comments

Comments
 (0)