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: handle empty display_name #26

Merged
merged 1 commit into from
Mar 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/generateMastodonEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const generateMastodonEmbed = async ({

return embedData;
} catch (error) {
console.error("Error fetching Mastodon post", error);
return null;
}
};
10 changes: 8 additions & 2 deletions src/utils/convertors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export const convertResponseToData = (
!response.account ||
!response.account.url ||
!response.account.username ||
!response.account.display_name ||
!response.account.avatar ||
!response.created_at
) {
console.error("Invalid Mastodon response", response);
return null;
}

Comment on lines 15 to 24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [124-124]

The use of dynamically generated regular expressions based on user input in the convertCustomEmojisToImages function could potentially lead to a Regular Expression Denial-of-Service (ReDoS) vulnerability. Consider using a regex checking/sanitization library such as recheck or performing input validation to ensure that the regex does not appear vulnerable to ReDoS. This precaution will help maintain the application's performance and security.

Expand All @@ -34,7 +34,13 @@ export const convertResponseToData = (
card,
emojis,
} = response;
const { url: accountUrl, username, display_name, avatar } = account;
const { url: accountUrl, username, avatar } = account;

// NOTE: sometimes instances return empty display_name, so we use the username as a fallback
let display_name = account.display_name;
if (!account.display_name) {
display_name = username;
}

return {
content,
Expand Down
1 change: 1 addition & 0 deletions src/utils/demoPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const demoPosts = [
"@[email protected]:112022457133862143", // with embedded github card
"@[email protected]:111943084834223099", // with embedded youtube card
"@[email protected]:111605128127230772", // with custom emoji
"@[email protected]:112054527697723909", // Issue #25, emplty display_name returned by mastodon.social
];