From fd460396edec6969e0dae683021a7bda577f6d79 Mon Sep 17 00:00:00 2001 From: cel Date: Sun, 28 May 2017 15:12:56 -1000 Subject: linkify url-encoded refs --- lib/render.js | 12 ++++++++++-- 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 -- cgit v1.2.3