Skip to content

Commit

Permalink
add escape html to htmlContent on conversation list
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Jan 13, 2022
1 parent 0a18ea1 commit 51768b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/javascript/packages/components/src/utils/htmlSanitize.ts
Expand Up @@ -2,3 +2,10 @@ export default function extractContent(html) {
return new DOMParser().parseFromString(html, 'text/html').documentElement
.textContent;
}

export function escapeHTML(unsafe) {
return unsafe.replace(
/[\u0000-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u00FF]/g,
(c) => '&#' + ('000' + c.charCodeAt(0)).substr(-4, 4) + ';'
);
}
6 changes: 4 additions & 2 deletions app/javascript/src/pages/conversations/ItemList.tsx
Expand Up @@ -2,7 +2,9 @@ import React from 'react';
import { Link } from 'react-router-dom';
import Moment from 'react-moment';
import { readableColor } from 'polished';
import sanitizeHtml from '@chaskiq/components/src/utils/htmlSanitize';
import sanitizeHtml, {
escapeHTML,
} from '@chaskiq/components/src/utils/htmlSanitize';
import { LabelIcon } from '@chaskiq/components/src/components/icons';
import Avatar from '@chaskiq/components/src/components/Avatar';

Expand All @@ -16,7 +18,7 @@ export default function ConversationItemList({ app, conversation }) {
const renderConversationContent = (o) => {
const message = o.lastMessage.message;
if (message.htmlContent) {
return sanitizeHtml(message.htmlContent).substring(0, 250);
return sanitizeHtml(escapeHTML(message.htmlContent)).substring(0, 250);
}
};

Expand Down

0 comments on commit 51768b2

Please sign in to comment.