File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ function ghGot(path, opts) {
12
12
opts = Object . assign ( {
13
13
json : true ,
14
14
token : env . GITHUB_TOKEN ,
15
- endpoint : env . GITHUB_ENDPOINT ? env . GITHUB_ENDPOINT . replace ( / [ ^ / ] $ / , '$&/' ) : 'https://api.github.com/'
15
+ endpoint : env . GITHUB_ENDPOINT ? env . GITHUB_ENDPOINT : 'https://api.github.com/'
16
16
} , opts ) ;
17
17
18
18
opts . headers = Object . assign ( {
@@ -29,7 +29,7 @@ function ghGot(path, opts) {
29
29
opts . headers [ 'content-length' ] = 0 ;
30
30
}
31
31
32
- const url = / ^ h t t p s ? / . test ( path ) ? path : opts . endpoint + path ;
32
+ const url = / ^ h t t p s ? / . test ( path ) ? path : opts . endpoint . replace ( / \/ $ / , '' ) + '/' + path . replace ( / ^ \/ / , '' ) ;
33
33
34
34
if ( opts . stream ) {
35
35
return got . stream ( url , opts ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ test('accepts options', async t => {
17
17
t . is ( ( await m ( 'users/sindresorhus' , { } ) ) . body . login , 'sindresorhus' ) ;
18
18
} ) ;
19
19
20
+ test ( 'accepts options.endpoint without trailing slash' , async t => {
21
+ t . is ( ( await m ( 'users/sindresorhus' , { endpoint : 'https://api.github.com' } ) ) . body . login , 'sindresorhus' ) ;
22
+ } ) ;
23
+
24
+ test ( 'dedupes slashes' , async t => {
25
+ t . is ( ( await m ( '/users/sindresorhus' , { endpoint : 'https://api.github.com/' } ) ) . body . login , 'sindresorhus' ) ;
26
+ } ) ;
27
+
20
28
test . serial ( 'global token option' , async t => {
21
29
process . env . GITHUB_TOKEN = 'fail' ;
22
30
await t . throws ( m ( 'users/sindresorhus' ) , 'Bad credentials (401)' ) ;
You can’t perform that action at this time.
0 commit comments