git ssb


0+

cel / patchfoo



Commit 3c09de63bc13f224fe98dce2e402050d4006b9cb

encode filename better

cel committed on 3/13/2017, 10:11:13 PM
Parent: e3fc312c8e31b4c99e3ecbdcbb890ffc2dc51f05

Files changed

lib/serve.jschanged
lib/serve.jsView
@@ -43,8 +43,12 @@
4343 case 'json': return 'application/json'
4444 }
4545 }
4646
47+function encodeDispositionFilename(fname) {
48+ return '"' + fname.replace(/\/g/, '\\\\').replace(/"/, '\\\"') + '"'
49+}
50+
4751 function Serve(app, req, res) {
4852 this.app = app
4953 this.req = req
5054 this.res = res
@@ -506,9 +510,9 @@
506510 ident(function (type) {
507511 type = type && mime.lookup(type)
508512 if (type) self.res.setHeader('Content-Type', type)
509513 if (self.query.name) self.res.setHeader('Content-Disposition',
510- 'inline; filename='+encodeURIComponent(self.query.name))
514+ 'attachment; filename='+encodeDispositionFilename(self.query.name))
511515 self.res.setHeader('Cache-Control', 'public, max-age=315360000')
512516 self.res.setHeader('etag', id)
513517 self.res.writeHead(200)
514518 }),

Built with git-ssb-web