Fix the error when no name in subscription by using the email address as the author when no author found in the newsletter

This commit is contained in:
Hongbo Wu 2023-01-10 11:17:22 +08:00
parent b7a4c2c92e
commit 1243e2ace2
2 changed files with 6 additions and 1 deletions

View file

@ -134,7 +134,7 @@ export abstract class ContentHandler {
// e.g. 'Jackson Harper from Omnivore App <jacksonh@substack.com>'
// or 'Mike Allen <mike@axios.com>'
const parsed = addressparser(from)
if (parsed.length > 0) {
if (parsed.length > 0 && parsed[0].name) {
return parsed[0].name
}
return from

View file

@ -93,6 +93,11 @@ describe('Newsletter email test', () => {
const from = 'Mike Allen <mike@axios.com>'
expect(new AxiosHandler().parseAuthor(from)).to.equal('Mike Allen')
})
it('returns email address if author is not there', () => {
const from = 'mike@axios.com'
expect(new AxiosHandler().parseAuthor(from)).to.equal(from)
})
})
describe('getNewsletterHandler', () => {