Skip to content

Commit

Permalink
fix: correct escape quotes in contributor names (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwmkerr committed May 12, 2023
1 parent 66d29af commit 959e361
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/generate/__tests__/fixtures/contributors.json
Expand Up @@ -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"]
}
}
9 changes: 9 additions & 0 deletions src/generate/__tests__/format-contributor.js
Expand Up @@ -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)
})
4 changes: 3 additions & 1 deletion src/generate/format-contributor.js
Expand Up @@ -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) {
Expand Down

0 comments on commit 959e361

Please sign in to comment.