diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/render.js | 12 | ||||
-rw-r--r-- | lib/util.js | 1 |
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/render.js b/lib/render.js index 02d7285..2c2278c 100644 --- a/lib/render.js +++ b/lib/render.js @@ -149,13 +149,21 @@ Render.prototype.formatSize = function (size) { } Render.prototype.linkify = function (text) { - var arr = text.split(u.ssbRefRegex) + var arr = text.split(u.ssbRefEncRegex) for (var i = 1; i < arr.length; i += 2) { - arr[i] = h('a', {href: this.toUrl(arr[i])}, arr[i]) + arr[i] = h('a', {href: this.toUrlEnc(arr[i])}, arr[i]) } return arr } +Render.prototype.toUrlEnc = function (href) { + var url = this.toUrl(href) + if (url) return url + try { href = decodeURIComponent(href) } + catch (e) { return false } + return this.toUrl(href) +} + Render.prototype.toUrl = function (href) { if (!href) return href var mentions = this._mentions diff --git a/lib/util.js b/lib/util.js index 267df9f..e8fc435 100644 --- a/lib/util.js +++ b/lib/util.js @@ -4,6 +4,7 @@ var h = require('hyperscript') var u = exports u.ssbRefRegex = /((?:@|%|&|ssb:\/\/%)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g +u.ssbRefEncRegex = /((?:ssb:\/\/)?(?:[@%&]|%26|%40|%25)(?:[A-Za-z0-9\/+]|%2[fF]|%2[bB]){43}(?:=|%3[dD])\.[\w\d]+)/g u.isRef = function (str) { if (!str) return false |