Commit 38f058f88ea3d8eb9e4f8ea5f16fb622289b3d88
Escape inner text of links by default
Charles Lehner committed on 3/26/2016, 6:42:07 PMParent: 0dcd8bc291330e6ea6c2e7fe6836238e1f68f702
Files changed
index.js | changed |
package.json | changed |
index.js | ||
---|---|---|
@@ -15,8 +15,9 @@ | ||
15 | 15 | var asyncMemo = require('asyncmemo') |
16 | 16 | var multicb = require('multicb') |
17 | 17 | var schemas = require('ssb-msg-schemas') |
18 | 18 | var Issues = require('ssb-issues') |
19 | +var paramap = require('pull-paramap') | |
19 | 20 | |
20 | 21 | marked.setOptions({ |
21 | 22 | gfm: true, |
22 | 23 | mentions: true, |
@@ -39,12 +40,13 @@ | ||
39 | 40 | function flattenPath(parts) { |
40 | 41 | return '/' + parts.map(encodeURIComponent).join('/') |
41 | 42 | } |
42 | 43 | |
43 | -function link(parts, html) { | |
44 | +function link(parts, text, raw) { | |
44 | 45 | var href = flattenPath(parts) |
45 | - var innerHTML = html == null ? escapeHTML(parts[parts.length-1]) : html | |
46 | - return '<a href="' + escapeHTML(href) + '">' + innerHTML + '</a>' | |
46 | + if (text == null) text = parts[parts.length-1] | |
47 | + if (!raw) text = escapeHTML(text) | |
48 | + return '<a href="' + escapeHTML(href) + '">' + text + '</a>' | |
47 | 49 | } |
48 | 50 | |
49 | 51 | function timestamp(time) { |
50 | 52 | time = Number(time) |
@@ -716,9 +718,9 @@ | ||
716 | 718 | if (err) return cb(err) |
717 | 719 | var commitPath = [repo.id, 'commit', commit.id] |
718 | 720 | var treePath = [repo.id, 'tree', commit.id] |
719 | 721 | cb(null, '<section class="collapse">' + |
720 | - '<strong>' + link(commitPath, escapeHTML(commit.title)) + '</strong><br>' + | |
722 | + '<strong>' + link(commitPath, commit.title) + '</strong><br>' + | |
721 | 723 | '<code>' + commit.id + '</code> ' + |
722 | 724 | link(treePath, 'Tree') + '<br>' + |
723 | 725 | (commit.separateAuthor ? escapeHTML(commit.author.name) + ' authored on ' + commit.author.date.toLocaleString() + '<br>' : '') + |
724 | 726 | escapeHTML(commit.committer.name) + ' committed on ' + commit.committer.date.toLocaleString() + |
@@ -766,9 +768,9 @@ | ||
766 | 768 | repo.getCommitParsed(rev, function (err, commit) { |
767 | 769 | if (err) return cb(err) |
768 | 770 | var commitPath = [repo.id, 'commit', commit.id] |
769 | 771 | cb(null, |
770 | - 'Latest: <strong>' + link(commitPath, escapeHTML(commit.title)) + | |
772 | + 'Latest: <strong>' + link(commitPath, commit.title) + | |
771 | 773 | '</strong><br>' + |
772 | 774 | '<code>' + commit.id + '</code><br> ' + |
773 | 775 | escapeHTML(commit.committer.name) + ' committed on ' + |
774 | 776 | commit.committer.date.toLocaleString() + |
@@ -859,9 +861,9 @@ | ||
859 | 861 | if (err) return cb(err) |
860 | 862 | var commitPath = [repo.id, 'commit', commit.id] |
861 | 863 | var treePath = [repo.id, 'tree', commit.tree] |
862 | 864 | cb(null, |
863 | - '<p><strong>' + link(commitPath, escapeHTML(commit.title)) + | |
865 | + '<p><strong>' + link(commitPath, commit.title) + | |
864 | 866 | '</strong></p>' + |
865 | 867 | pre(commit.body) + |
866 | 868 | '<p>' + |
867 | 869 | (commit.separateAuthor ? escapeHTML(commit.author.name) + |
@@ -925,9 +927,9 @@ | ||
925 | 927 | } |
926 | 928 | |
927 | 929 | function renderObject(obj) { |
928 | 930 | return '<section class="collapse">' + |
929 | - obj.type + ' ' + link([obj.link], escapeHTML(obj.sha1)) + '<br>' + | |
931 | + obj.type + ' ' + link([obj.link], obj.sha1) + '<br>' + | |
930 | 932 | obj.length + ' bytes' + |
931 | 933 | '</section>' |
932 | 934 | } |
933 | 935 | |
@@ -1051,9 +1053,9 @@ | ||
1051 | 1053 | return renderRepoPage(repo, '', cat([ |
1052 | 1054 | pull.once( |
1053 | 1055 | (isPublic ? '' : |
1054 | 1056 | '<div class="right-bar">' + link([repo.id, 'issues', 'new'], |
1055 | - '<button>+ New Issue</button>') + | |
1057 | + '<button>+ New Issue</button>', true) + | |
1056 | 1058 | '</div>') + |
1057 | 1059 | '<h3>Issues</h3>'), |
1058 | 1060 | pull( |
1059 | 1061 | issues.createFeedStream({ project: repo.id }), |
Built with git-ssb-web