From 959e3613bf57f575514375e26be9856cb51fed02 Mon Sep 17 00:00:00 2001 From: Dave Kerr Date: Sat, 13 May 2023 07:00:21 +0800 Subject: [PATCH] fix: correct escape quotes in contributor names (#351) --- src/generate/__tests__/fixtures/contributors.json | 7 +++++++ src/generate/__tests__/format-contributor.js | 9 +++++++++ src/generate/format-contributor.js | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/generate/__tests__/fixtures/contributors.json b/src/generate/__tests__/fixtures/contributors.json index 7ede43c..ff4a1c4 100644 --- a/src/generate/__tests__/fixtures/contributors.json +++ b/src/generate/__tests__/fixtures/contributors.json @@ -34,5 +34,12 @@ "name": "Wildly Misconfigured", "avatar_url": "https://avatars1.githubusercontent.com/u/1500684", "contributions": ["plumbis"] + }, + "name_with_quotes": { + "login": "namelastname", + "name": "Name \"Nickname\" Lastname", + "avatar_url": "https://avatars1.githubusercontent.com/u/1500684", + "profile": "http://github.com/namelastname", + "contributions": ["doc"] } } diff --git a/src/generate/__tests__/format-contributor.js b/src/generate/__tests__/format-contributor.js index c158cb3..e9ebde8 100644 --- a/src/generate/__tests__/format-contributor.js +++ b/src/generate/__tests__/format-contributor.js @@ -87,3 +87,12 @@ test('format contributor with no complete name', () => { expect(formatContributor(options, contributor)).toBe(expected) }) + +test('format contributor with quotes in name', () => { + const contributor = contributors.name_with_quotes + const {options} = fixtures() + + const expected = + 'Name "Nickname" Lastname
Name "Nickname" Lastname

📖' + expect(formatContributor(options, contributor)).toBe(expected) +}) diff --git a/src/generate/format-contributor.js b/src/generate/format-contributor.js index 9f489f4..5a86e83 100644 --- a/src/generate/format-contributor.js +++ b/src/generate/format-contributor.js @@ -44,7 +44,9 @@ function defaultTemplate(templateData) { } function escapeName(name) { - return name.replace(new RegExp('\\|', 'g'), '|') + return name + .replace(new RegExp('\\|', 'g'), '|') + .replace(new RegExp('\\"', 'g'), '"') } module.exports = function formatContributor(options, contributor) {