aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2020-02-27 13:33:23 -0500
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2020-02-27 13:33:23 -0500
commitb5cec405f40f6e5b5d444613f5f2f6ebc42507aa (patch)
treeb2c16ac4a23a2d62b4c7b538a2016e002a4dc8c8
parente1a9df691c91e6793204528df331894efe952484 (diff)
downloadpatchfoo-b5cec405f40f6e5b5d444613f5f2f6ebc42507aa.tar.gz
patchfoo-b5cec405f40f6e5b5d444613f5f2f6ebc42507aa.zip
Fix blob filename handling
Make links to HTML blobs not prompt to download
-rw-r--r--lib/render.js7
-rw-r--r--lib/serve.js6
2 files changed, 8 insertions, 5 deletions
diff --git a/lib/render.js b/lib/render.js
index 680ba39..31ed74c 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -47,6 +47,10 @@ MdRenderer.prototype.image = function (ref, title, text) {
MdRenderer.prototype.link = function (ref, title, text) {
var href = this.urltransform(ref)
var name = href && /^\/(&|%26)/.test(href) && (title || text)
+ if (name) {
+ href += (/\?/.test(href) ? '&' : '?') +
+ 'filename=' + encodeURIComponent(name)
+ }
if (u.isRef(ref)) {
var myName = this.render.app.getNameSync(ref)
if (myName) title = title ? title + ' (' + myName + ')' : myName
@@ -55,8 +59,7 @@ MdRenderer.prototype.link = function (ref, title, text) {
var a = h('a', {
class: href === false ? 'bad' : undefined,
href: href !== false ? hrefToken : undefined,
- title: title || undefined,
- download: name ? encodeURIComponent(name) : undefined
+ title: title || undefined
})
// text is already html-escaped
a.innerHTML = text
diff --git a/lib/serve.js b/lib/serve.js
index 96f8313..556e70f 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -48,7 +48,7 @@ function ctype(name) {
}
function encodeDispositionFilename(fname) {
- fname = fname.replace(/\/g/, '\\\\').replace(/"/, '\\\"')
+ fname = String(fname).replace(/\/g/, '\\\\').replace(/"/, '\\\"')
return '"' + encodeURIComponent(fname) + '"'
}
@@ -1570,7 +1570,7 @@ Serve.prototype.blob = function (id, path) {
if (typeof size === 'number' && !key)
self.res.setHeader('Content-Length', size)
if (self.query.filename) self.res.setHeader('Content-Disposition',
- 'inline; filename='+encodeDispositionFilename(self.query.name))
+ 'inline; filename='+encodeDispositionFilename(self.query.filename))
if (self.query.gzip)
self.res.setHeader('Content-Encoding', 'gzip')
if (self.query.contentType)
@@ -1656,7 +1656,7 @@ Serve.prototype.image = function (path) {
if (type) self.res.setHeader('Content-Type', type)
self.res.setHeader('Content-Length', data.length)
if (self.query.filename) self.res.setHeader('Content-Disposition',
- 'inline; filename='+encodeDispositionFilename(self.query.name))
+ 'inline; filename='+encodeDispositionFilename(self.query.filename))
if (self.query.gzip)
self.res.setHeader('Content-Encoding', 'gzip')
if (self.query.contentType)