Skip to content

Commit 959e361

Browse files
authoredMay 12, 2023
fix: correct escape quotes in contributor names (#351)
1 parent 66d29af commit 959e361

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
 

‎src/generate/__tests__/fixtures/contributors.json

+7
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,12 @@
3434
"name": "Wildly Misconfigured",
3535
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
3636
"contributions": ["plumbis"]
37+
},
38+
"name_with_quotes": {
39+
"login": "namelastname",
40+
"name": "Name \"Nickname\" Lastname",
41+
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
42+
"profile": "http://github.com/namelastname",
43+
"contributions": ["doc"]
3744
}
3845
}

‎src/generate/__tests__/format-contributor.js

+9
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,12 @@ test('format contributor with no complete name', () => {
8787

8888
expect(formatContributor(options, contributor)).toBe(expected)
8989
})
90+
91+
test('format contributor with quotes in name', () => {
92+
const contributor = contributors.name_with_quotes
93+
const {options} = fixtures()
94+
95+
const expected =
96+
'<a href="http://github.com/namelastname"><img src="https://avatars1.githubusercontent.com/u/1500684?s=150" width="150px;" alt="Name &quot;Nickname&quot; Lastname"/><br /><sub><b>Name &quot;Nickname&quot; Lastname</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=namelastname" title="Documentation">📖</a>'
97+
expect(formatContributor(options, contributor)).toBe(expected)
98+
})

‎src/generate/format-contributor.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ function defaultTemplate(templateData) {
4444
}
4545

4646
function escapeName(name) {
47-
return name.replace(new RegExp('\\|', 'g'), '&#124;')
47+
return name
48+
.replace(new RegExp('\\|', 'g'), '&#124;')
49+
.replace(new RegExp('\\"', 'g'), '&quot;')
4850
}
4951

5052
module.exports = function formatContributor(options, contributor) {

0 commit comments

Comments
 (0)
Please sign in to comment.