Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(middleware:mapped): Ensure pathnames are not incorrectly updated if no url matches #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/middleware/mapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(mappedPaths) {

function mapUrl(urlPath) {
var urlObj = url.parse(urlPath.toString())
urlObj.pathname = mappedPaths[urlObj.pathname] || urlPath
urlObj.pathname = mappedPaths[urlObj.pathname] || urlObj.pathname
return url.format(urlObj)
}

Expand Down
12 changes: 10 additions & 2 deletions test/mapped-versionator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,21 @@ describe('versionator', function() {
mapped.modifyMap({ '/js/test.js': '/js/OTHERHASH/test.js' })
mapped.versionPath('/js/test.js').should.eql('/js/OTHERHASH/test.js')
})
it('strings without a "/" will be left unchanged', function() {
it('strings without a "/" will be encoded correctly', function() {
var mapped = versionator.createMapped({
'/js/test.js': '/js/HASH/test.js'
})
mapped
.versionPath('Hello this is an odd path')
.should.eql('Hello this is an odd path')
.should.eql('Hello%20this%20is%20an%20odd%20path')
})
it('strings with a hash and no match will be encoded correctly', function() {
var mapped = versionator.createMapped({
'/js/test.js': '/js/HASH/test.js'
})
mapped
.versionPath('/test/ing#hashparam')
.should.eql('/test/ing#hashparam')
})

it('should convert all URLs in an array', function() {
Expand Down