fix: correct escape quotes in contributor names (#351)

This commit is contained in:
Dave Kerr 2023-05-13 07:00:21 +08:00 committed by GitHub
parent 66d29afac5
commit 959e3613bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -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"]
}
}

View file

@ -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 =
'<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>'
expect(formatContributor(options, contributor)).toBe(expected)
})

View file

@ -44,7 +44,9 @@ function defaultTemplate(templateData) {
}
function escapeName(name) {
return name.replace(new RegExp('\\|', 'g'), '&#124;')
return name
.replace(new RegExp('\\|', 'g'), '&#124;')
.replace(new RegExp('\\"', 'g'), '&quot;')
}
module.exports = function formatContributor(options, contributor) {