From 1013706d436cbf44cd70704ccc8194ae85ae0416 Mon Sep 17 00:00:00 2001 From: Chris Vickery Date: Thu, 6 Apr 2017 13:08:55 -0700 Subject: [PATCH] Support pipe characters in github names --- lib/generate/fixtures/contributors.json | 9 +++++++++ lib/generate/format-contributor.js | 12 ++++++++++-- lib/generate/format-contributor.test.js | 9 +++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/generate/fixtures/contributors.json b/lib/generate/fixtures/contributors.json index 80320363..8e54dbdb 100644 --- a/lib/generate/fixtures/contributors.json +++ b/lib/generate/fixtures/contributors.json @@ -18,5 +18,14 @@ "contributions": [ "review" ] + }, + "pipey": { + "login": "pipey", + "name": "Who | Needs | Pipes?", + "profile": "http://github.com/chrisinajar", + "avatar_url": "https://avatars1.githubusercontent.com/u/1500684", + "contributions": [ + "doc" + ] } } diff --git a/lib/generate/format-contributor.js b/lib/generate/format-contributor.js index 60479fed..24f53cbb 100644 --- a/lib/generate/format-contributor.js +++ b/lib/generate/format-contributor.js @@ -4,17 +4,25 @@ var _ = require('lodash/fp'); var formatContributionType = require('./format-contribution-type'); var avatarTemplate = _.template(''); -var avatarBlockTemplate = _.template('[<%= avatar %>
<%= contributor.name %>](<%= contributor.profile %>)'); +var avatarBlockTemplate = _.template('[<%= avatar %>
<%= name %>](<%= contributor.profile %>)'); var contributorTemplate = _.template('<%= avatarBlock %>
<%= contributions %>'); var defaultImageSize = 100; function defaultTemplate(templateData) { var avatar = avatarTemplate(templateData); - var avatarBlock = avatarBlockTemplate(_.assign({avatar: avatar}, templateData)); + var avatarBlock = avatarBlockTemplate(_.assign({ + name: escapeName(templateData.contributor.name), + avatar: avatar + }, templateData)); + return contributorTemplate(_.assign({avatarBlock: avatarBlock}, templateData)); } +function escapeName(name) { + return name.replace(new RegExp('\\|', 'g'), '|'); +} + module.exports = function formatContributor(options, contributor) { var formatter = _.partial(formatContributionType, [options, contributor]); var contributions = contributor.contributions diff --git a/lib/generate/format-contributor.test.js b/lib/generate/format-contributor.test.js index fa6cae01..f9d29a96 100644 --- a/lib/generate/format-contributor.test.js +++ b/lib/generate/format-contributor.test.js @@ -49,3 +49,12 @@ test('should default image size to 100', t => { t.is(formatContributor(options, contributor), expected); }); + +test('should format contributor with pipes in their name', t => { + const contributor = contributors.pipey; + const {options} = fixtures(); + + const expected = '[
Who | Needs | Pipes?](http://github.com/chrisinajar)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=pipey)'; + + t.is(formatContributor(options, contributor), expected); +});