aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-08-23 12:39:53 -0700
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-08-23 12:39:53 -0700
commit679e08e0da36f829ffd8ec60e9e3beecab4b5925 (patch)
tree9c3c04293ad16d65df65beb7aae27cbe77dfc1e7
parent369f72529e83414099bdf037c3015cc9f61a038d (diff)
downloadpatchfoo-679e08e0da36f829ffd8ec60e9e3beecab4b5925.tar.gz
patchfoo-679e08e0da36f829ffd8ec60e9e3beecab4b5925.zip
Unescape HTML in image names for alt text
-rw-r--r--lib/markdown-inline.js7
-rw-r--r--lib/render.js2
-rw-r--r--lib/util.js9
3 files changed, 11 insertions, 7 deletions
diff --git a/lib/markdown-inline.js b/lib/markdown-inline.js
index e2d40f8..0d4b89f 100644
--- a/lib/markdown-inline.js
+++ b/lib/markdown-inline.js
@@ -1,5 +1,6 @@
var marked = require('ssb-marked')
var u = require('./util')
+var unquote = u.unescapeHTML
// based on ssb-markdown, which is Copyright (c) 2016 Dominic Tarr, MIT License
@@ -28,12 +29,6 @@ inlineRenderer.del = function(text) { return unquote(text) }
inlineRenderer.mention = function(preceding, id) { return shortenIfLink(unquote((preceding||'') + id)) }
inlineRenderer.hashtag = function(preceding, tag) { return unquote((preceding||'') + tag) }
-function unquote (text) {
- return text.replace(/&amp;/g, '&').replace(/&quot;/g, '"').replace(/&#39;/g, '\'')
- .replace(/&gt;/g, '>')
- .replace(/&lt;/g, '<')
-}
-
function shortenIfLink (text) {
return (u.ssbRefRegex.test(text.trim())) ? text.slice(0, 8) : text
}
diff --git a/lib/render.js b/lib/render.js
index 045cf86..dbfd673 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -179,7 +179,7 @@ Render.prototype.imageUrl = function (ref) {
Render.prototype.getImageAlt = function (id, fallback) {
var link = this._mentionsByLink[id]
if (!link) return fallback
- var name = link.name || fallback
+ var name = u.unescapeHTML(link.name || fallback)
return name
+ (link.size != null ? ' (' + this.formatSize(link.size) + ')' : '')
}
diff --git a/lib/util.js b/lib/util.js
index 9f17966..58bb4b0 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -169,6 +169,15 @@ u.escapeHTML = function (html) {
.replace(/>/g, '&gt;')
}
+u.unescapeHTML = function (text) {
+ if (typeof text !== 'string') return text
+ return text.replace(/&amp;/g, '&')
+ .replace(/&quot;/g, '"')
+ .replace(/&#39;/g, '\'')
+ .replace(/&gt;/g, '>')
+ .replace(/&lt;/g, '<')
+}
+
u.pullSlice = function (start, end) {
if (end == null) end = Infinity
var offset = 0