Skip to content

Commit

Permalink
tests(web-server): add unit test for utf8 chars in basePath
Browse files Browse the repository at this point in the history
This is based on #648
  • Loading branch information
vojtajina committed Jul 31, 2013
1 parent ed3cb27 commit 5be66e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/middleware/source-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var createSourceFilesMiddleware = function(filesPromise, serveFile,
/* config.basePath */ basePath) {

return function(request, response, next) {
var requestedFilePath = querystring.unescape(request.url.replace(/\?.*/, ''))
var requestedFilePath = querystring.unescape(request.url)
.replace(/\?.*/, '')
.replace(/^\/absolute/, '')
.replace(/^\/base/, basePath);

Expand Down
20 changes: 19 additions & 1 deletion test/unit/middleware/source-files.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe 'middleware.source-files', ->
'a.js': mocks.fs.file(0, 'js-src-a')
src:
'some.js': mocks.fs.file(0, 'js-source')
'utf8ášč':
'some.js': mocks.fs.file(0, 'utf8-file')


serveFile = require('../../../lib/middleware/common').createServeFile fsMock, null
createSourceFilesMiddleware = require('../../../lib/middleware/source-files').create
Expand Down Expand Up @@ -113,5 +116,20 @@ describe 'middleware.source-files', ->
expect(response).to.beServedAs 404, 'NOT FOUND'
done()

callHandlerWith '/absolute/non-existing.js', ->
callHandlerWith '/absolute/non-existing.js'


it 'should serve js source file from base path containing utf8 chars', (done) ->
servedFiles [
new File('/utf8ášč/some.js')
]

handler = createSourceFilesMiddleware filesDeferred.promise, serveFile, '/utf8ášč'

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
expect(response._body).to.equal 'utf8-file'
expect(response._status).to.equal 200
done()

callHandlerWith '/base/some.js'

0 comments on commit 5be66e2

Please sign in to comment.