Skip to content

Commit

Permalink
Make sure we don't escape %2B for S3
Browse files Browse the repository at this point in the history
Fixes #115
Regression introduced by 2bae4be
  • Loading branch information
mhart committed Aug 12, 2020
1 parent d34f46a commit 6b5da6f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws4.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ RequestSigner.prototype.canonicalString = function() {
if (normalizePath && piece === '..') {
path.pop()
} else if (!normalizePath || piece !== '.') {
if (decodePath) piece = decodeURIComponent(piece).replace(/\+/g, ' ')
if (decodePath) piece = decodeURIComponent(piece.replace(/\+/g, ' '))
path.push(encodeRfc3986Full(piece))
}
return path
Expand Down
36 changes: 36 additions & 0 deletions test/fast.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,42 @@ describe('aws4', function() {
signer.sign().path.should.equal('/%2f%2f')
})

it('should decode + as space with s3', function() {
var signer = new RequestSigner({service: 's3', path: '/++'})
var canonical = signer.canonicalString().split('\n')

canonical[1].should.equal('/%20%20')
canonical[2].should.equal('')
signer.sign().path.should.equal('/++')
})

it('should just leave + on non-s3', function() {
var signer = new RequestSigner({service: 'es', path: '/++'})
var canonical = signer.canonicalString().split('\n')

canonical[1].should.equal('/%2B%2B')
canonical[2].should.equal('')
signer.sign().path.should.equal('/++')
})

it('should decode %2B with s3', function() {
var signer = new RequestSigner({service: 's3', path: '/%2b%2b'})
var canonical = signer.canonicalString().split('\n')

canonical[1].should.equal('/%2B%2B')
canonical[2].should.equal('')
signer.sign().path.should.equal('/%2b%2b')
})

it('should just escape %2B on non-s3', function() {
var signer = new RequestSigner({service: 'es', path: '/%2b%2b'})
var canonical = signer.canonicalString().split('\n')

canonical[1].should.equal('/%252b%252b')
canonical[2].should.equal('')
signer.sign().path.should.equal('/%2b%2b')
})

it('should work with mixed chars > 127 and < 255 and percent encoding with s3', function() {
var signer = new RequestSigner({service: 's3', path: '/ü%41'})
var canonical = signer.canonicalString().split('\n')
Expand Down

0 comments on commit 6b5da6f

Please sign in to comment.