-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from DishpitDev/staging
ligma
- Loading branch information
Showing
25 changed files
with
219 additions
and
63 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,76 @@ | ||
import emojis, { EMOJI_REGEX, createEmojiElement } from "../utils/emoji.js"; | ||
|
||
function sanitizeHTML(message) { | ||
// purges script tags | ||
message = message.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, ''); | ||
message = message.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, ""); | ||
|
||
// purges iframe tags | ||
message = message.replace(/<iframe[^>]*>([\s\S]*?)<\/iframe>/gi, ''); | ||
message = message.replace(/<iframe[^>]*>([\s\S]*?)<\/iframe>/gi, ""); | ||
|
||
// purges object tags | ||
message = message.replace(/<(object|embed|applet)[^>]*>[\s\S]*?<\/\1>/gi, ''); | ||
message = message.replace(/<(object|embed|applet)[^>]*>[\s\S]*?<\/\1>/gi, ""); | ||
|
||
// purges event handlers | ||
message = message.replace(/<([a-z][a-z0-9]*)\s+[^>]*\s*on\w+="[^"]*"[^>]*>/gi, '<$1>'); | ||
message = message.replace( | ||
/<([a-z][a-z0-9]*)\s+[^>]*\s*on\w+="[^"]*"[^>]*>/gi, | ||
"<$1>", | ||
); | ||
|
||
return message; | ||
} | ||
|
||
function processEmojis(message) { | ||
const emojis = message.match(EMOJI_REGEX); | ||
|
||
if (!emojis) { | ||
return message; | ||
} | ||
|
||
for (let emoji of emojis) { | ||
const emojiElement = createEmojiElement(emoji.slice(1, -1)); | ||
if (!emojiElement) { | ||
continue; | ||
} | ||
message = message.replace(emoji, emojiElement); | ||
} | ||
|
||
return message; | ||
} | ||
|
||
export default function Message(data) { | ||
const sanitizedMessage = sanitizeHTML(data.message); | ||
const finalMessage = processEmojis(sanitizedMessage); | ||
|
||
return ( | ||
<> | ||
<div key={data.key} className="message"> | ||
<div | ||
style={{ | ||
display: "flex", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
}} | ||
> | ||
<div style={{ display: "flex", gap: "10px", maxWidth: "90%" }}> | ||
<img | ||
src={data.photo} | ||
alt="Profile" | ||
style={{ | ||
width: "50px", | ||
height: "50px", | ||
objectFit: "cover", | ||
borderRadius: "50%", | ||
}} | ||
<div key={data.id} className="message"> | ||
<div | ||
style={{ | ||
display: "flex", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
}} | ||
> | ||
<div style={{ display: "flex", gap: "10px", maxWidth: "90%" }}> | ||
<img | ||
src={data.photo} | ||
alt="Profile" | ||
style={{ | ||
width: "50px", | ||
height: "50px", | ||
objectFit: "cover", | ||
borderRadius: "50%", | ||
}} | ||
/> | ||
<div style={{ maxWidth: "90%" }}> | ||
<strong style={{ color: data.color }}>{data.name}</strong> | ||
<p | ||
style={{ margin: 0, marginTop: "0.5rem" }} | ||
dangerouslySetInnerHTML={{ __html: finalMessage }} | ||
/> | ||
<div style={{ maxWidth: "90%" }}> | ||
<strong style={{ color: data.color }}>{data.name}</strong> | ||
<p style={{ margin: 0, marginTop: "0.5rem" }}><p | ||
style={{ margin: 0, marginTop: "0.5rem" }} | ||
dangerouslySetInnerHTML={{ __html: sanitizedMessage }} | ||
/></p> | ||
</div> | ||
</div> | ||
<small style={{ minWidth: "15%" }}>{data.date}</small> | ||
</div> | ||
<small style={{ minWidth: "15%" }}>{data.date}</small> | ||
</div> | ||
</> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.