-
Notifications
You must be signed in to change notification settings - Fork 1
Code Bugs Repair
As part of Sprint 4, we identified and resolved several code issues flagged by static analysis tools such as SonarQube and ESLint. This document outlines five key bug fixes applied across the ChatHaven codebase. Each fix includes the issue description, the linter tool used, before/after code, and associated commit info.
File: MemberDM.jsx
Tool: SonarQube
Issue ID: SQ-UI-102
Problem: Message bubbles used inline styling, causing inconsistent layout across devices and violating accessibility standards.
<div style={{ marginBottom: "8px" }}>
<div style={{ fontSize: "14px" }}>{msg.message}</div>
</div><div className="message-bubble">
<div className="message-text">{msg.message}</div>
</div>Resolution: Refactored message styling into reusable CSS classes.
Commit: bf34ac1 - Refactored message bubble styles into reusable classes
File: Login.jsx, Signup.jsx
Tool: ESLint
Issue: The password visibility toggle only changed to text but never back to password. Input validation was also hardcoded.
<img onClick={(e) => {
const passwordField = e.target.previousSibling;
passwordField.type = "text";
}} /><img onClick={(e) => {
const passwordField = e.target.previousSibling;
passwordField.type =
passwordField.type === "password" ? "text" : "password";
}} />Resolution: Toggle now works both ways. Validation logic modularized.
Commit: 98c7be3 - Improved password toggle logic and abstracted validation
File: MemberDM.jsx
Tool: SonarQube
Issue ID: SQ-JSON-205
Problem: Replies that quoted messages with quotes caused JSON parsing to fail, breaking rendering.
function parseChatMessage(message) {
return JSON.parse(message);
}function parseChatMessage(message) {
try {
const parsed = JSON.parse(message);
if (parsed && parsed.reply && parsed.message) {
return { text: parsed.message, replyData: parsed.reply };
}
} catch (e) {
// fallback
}
return { text: message, replyData: null };
}Resolution: Safer parsing with fallback for raw strings.
Commit: 34f5de2 - Improved quoting logic and crash recovery for nested replies
File: MembersList.jsx
Tool: SonarQube
Issue ID: SQ-ASYNC-308
Problem: Race conditions and repeated state updates led to unreliable "away/online/offline" status and last_seen data.
window.addEventListener("mousemove", handleActivity);
window.addEventListener("keydown", handleActivity);let debounceTimer;
const handleActivity = () => {
clearTimeout(debounceTimer);
setStatus("online");
debounceTimer = setTimeout(() => setStatus("away"), 60000);
};
window.addEventListener("mousemove", handleActivity);
window.addEventListener("keydown", handleActivity);Resolution: Introduced debouncing to prevent redundant updates.
Commit: 7ad9f1b - Debounced activity tracking and fixed last seen sync
File: MemberDM.jsx, ChannelDM.jsx
Tool: SonarQube
Issue ID: SQ-SEC-415
Problem: Messages quoted multiple times nested HTML unnecessarily, making them unreadable. Potential XSS if media was unsanitized.
reply: {
message: replyMessage.message,
sender: friendProfile.username
}reply: {
message: originalMessage.replace(/(^"+|"+$)/g, ""),
sender: replyMessage.user_id === currentUser.id ? "You" : friendProfile.username || "Unknown",
senderId: replyMessage.user_id
}Resolution: Strips redundant quotation marks and escapes media content.
Commit: c0b8ef4 - Streamlined quoting logic and added media sanitization
| Commit Hash | Description |
|---|---|
bf34ac1 |
Refactored message bubble styles into reusable classes |
98c7be3 |
Improved password toggle logic and abstracted validation |
34f5de2 |
Improved quoting logic and crash recovery for nested replies |
7ad9f1b |
Debounced activity tracking and fixed last seen sync |
c0b8ef4 |
Streamlined quoting logic and added media sanitization |