Skip to content

Commit

Permalink
Merge pull request #662 from browniebroke/bugfix/foward-slashes
Browse files Browse the repository at this point in the history
Keep forward slashes in URL if they're present
  • Loading branch information
honzajavorek committed Nov 23, 2016
2 parents d504896 + b5c3357 commit 3897e6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/transaction-runner.coffee
Expand Up @@ -352,7 +352,10 @@ class TransactionRunner
# See also https://github.com/joyent/node/issues/2216
segments = [serverPath, requestPath]
segments = (segment.replace(/^\/|\/$/g, '') for segment in segments)
return '/' + segments.join('/')
# Keep trailing slash at the end if specified in requestPath
# and if requestPath isn't only '/'
trailingSlash = if requestPath isnt '/' and requestPath.slice(-1) is '/' then '/' else ''
return '/' + segments.join('/') + trailingSlash

# Factory for 'transaction.test' object creation
createTest: (transaction) ->
Expand Down
7 changes: 7 additions & 0 deletions test/unit/transaction-runner-test.coffee
Expand Up @@ -348,6 +348,13 @@ describe 'TransactionRunner', ->
assert.strictEqual configuredTransaction.fullPath, '/my/path/to/api' + '/machines'
done()

it 'should keep trailing slash in url if present', (done) ->
transaction.request.uri = '/machines/'
runner.configureTransaction transaction, (err, configuredTransaction) ->
assert.equal configuredTransaction.id, 'POST /machines/'
assert.strictEqual configuredTransaction.fullPath, '/my/path/to/api' + '/machines/'
done()

describe 'executeTransaction(transaction, callback)', ->

beforeEach ->
Expand Down

0 comments on commit 3897e6c

Please sign in to comment.