Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Allow :// to occur in the path even when baseUrl is used, as long as …
Browse files Browse the repository at this point in the history
…its not at the beginning

Cherry-pick 6601743
  • Loading branch information
johnnysprinkles authored and kevinvanrijn committed Sep 24, 2024
1 parent 45d9254 commit fdb61db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion request.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ Request.prototype.init = function (options) {
return self.emit('error', new Error('options.uri must be a string when using options.baseUrl'))
}

if (self.uri.indexOf('//') === 0 || self.uri.indexOf('://') !== -1) {
if (self.uri.indexOf('//') === 0 || self.uri.match(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//)) {
return self.emit('error', new Error('options.uri must be a path when using options.baseUrl'))
}

Expand Down
9 changes: 9 additions & 0 deletions tests/test-baseUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,12 @@ tape('error on baseUrl and uri with scheme-relative url', function (t) {
t.end()
})
})

tape('no error when scheme occurs later in path', function (t) {
request('/login?next=http://yourhome.com', {
baseUrl: s.url + '/path/'
}, function (err, resp, body) {
t.equal(err, null)
t.end()
})
})

0 comments on commit fdb61db

Please sign in to comment.