Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct escape quotes in contributor names #351

Merged
merged 3 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/generate/__tests__/fixtures/contributors.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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