aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-28 15:12:56 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-28 18:32:36 -1000
commitfd460396edec6969e0dae683021a7bda577f6d79 (patch)
tree242a8c0e72519badc075165ce98724b64576d5e8
parentdd3e70672100b33e373e0fa69e56767b600bb6ec (diff)
downloadpatchfoo-fd460396edec6969e0dae683021a7bda577f6d79.tar.gz
patchfoo-fd460396edec6969e0dae683021a7bda577f6d79.zip
linkify url-encoded refs
-rw-r--r--lib/render.js12
-rw-r--r--lib/util.js1
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