Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoevanp committed Jan 14, 2022
2 parents b5f0cce + 43b0404 commit 8da8b8b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 36 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## 1.11.2 - 2022-01-10
[FIX] IME not working properly #674

## 1.11.1 - 2021-12-30
[FIX] Hide Livechat if Omnichannel is disabled #671

## 1.11.0 - 2021-12-09
[NEW] Introduce clearLocalStorageWhenChatEnded setting logic (#666)
[IMPROVE] Change logic to generate token on Live Chat (#667)

## 1.10.0 - 2021-11-22
[NEW] Audio and Video calling in Livechat using WebRTC (#646)
[FIX] LoadConfig after registering guest (#640)
[FIX] Body styles getting overridden (#660)

## 1.9.6 - 2021-10-20
[FIX] 'Hide agent info' not working on system message (#651)
[FIX] Issues on Custom Livechat messages (#648)

## 1.9.5 - 2021-09-14
[IMPROVE] Readme enhancements (#557)
[IMPROVE] Swedish Translations (#573)
[FIX] Escaping HTML on paste/drop Text (#471)
[IMPROVE] Spanish translations (#370)
[IMPROVE] Russian translations (#644)
[IMPROVE] Add cookie to identify widget calls (#645)

## 1.9.4 - 2021-08-19
[FIX] Iframe overlay (#631)
[IMPROVE] German informal translation (#622)
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rocket.chat/livechat",
"version": "1.9.4",
"version": "1.11.2",
"files": [
"/build"
],
Expand Down Expand Up @@ -91,7 +91,6 @@
"css-vars-ponyfill": "^2.3.2",
"date-fns": "^2.15.0",
"desvg": "^1.0.2",
"dompurify": "^2.2.6",
"emoji-mart": "^3.0.0",
"history": "^5.0.0",
"i18nline": "^2.0.1",
Expand Down
7 changes: 4 additions & 3 deletions src/components/Composer/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { h, Component } from 'preact';

import { createClassName } from '../helpers';
import { createClassName, parse } from '../helpers';
import styles from './styles.scss';

const findLastTextNode = (node) => {
Expand Down Expand Up @@ -75,7 +75,8 @@ export class Composer extends Component {
items.filter((item) => item.kind === 'string' && /^text\/plain/.test(item.type))
.map((item) => new Promise((resolve) => item.getAsString(resolve))),
);
texts.forEach((text) => this.pasteText(text));

texts.forEach((text) => this.pasteText(parse(text)));
}

handleDrop = (onUpload) => async (event) => {
Expand All @@ -98,7 +99,7 @@ export class Composer extends Component {
items.filter((item) => item.kind === 'string' && /^text\/plain/.test(item.type))
.map((item) => new Promise((resolve) => item.getAsString(resolve))),
);
texts.forEach((text) => this.pasteText(text));
texts.forEach((text) => this.pasteText(parse(text)));
}

handleClick = () => {
Expand Down
3 changes: 1 addition & 2 deletions src/components/Messages/MessageText/markdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { sanitize } from 'dompurify';
import MarkdownIt from 'markdown-it';


Expand Down Expand Up @@ -81,4 +80,4 @@ md.use((md) => {
});
});

export const renderMarkdown = (...args) => sanitize(md.render(...args), { ADD_ATTR: ['target', 'rel'] });
export const renderMarkdown = (...args) => md.render(...args);
21 changes: 21 additions & 0 deletions src/components/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import parseISO from 'date-fns/parseISO';
import mem from 'mem';
import { Component } from 'preact';

import { Livechat, useSsl } from '../api';
Expand Down Expand Up @@ -262,3 +263,23 @@ export const resolveDate = (dateInput) => {
}
}
};

const escapeMap = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'\'': '&#x27;',
'`': '&#x60;',
};

const escapeRegex = new RegExp(`(?:${ Object.keys(escapeMap).join('|') })`, 'g');

const escapeHtml = mem(
(string) => string.replace(escapeRegex, (match) => escapeMap[match]),
);

export const parse = (plainText) =>
[{ plain: plainText }]
.map(({ plain, html }) => (plain ? escapeHtml(plain) : html || ''))
.join('');
26 changes: 2 additions & 24 deletions src/routes/Chat/container.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { sanitize } from 'dompurify';
import mem from 'mem';
import { h, Component } from 'preact';
import { route } from 'preact-router';

import { Livechat } from '../../api';
import { ModalManager } from '../../components/Modal';
import { debounce, getAvatarUrl, canRenderMessage, throttle, upsert } from '../../components/helpers';
import { debounce, getAvatarUrl, canRenderMessage, throttle, upsert, parse } from '../../components/helpers';
import I18n from '../../i18n';
import { normalizeQueueAlert } from '../../lib/api';
import constants from '../../lib/constants';
Expand Down Expand Up @@ -115,30 +113,10 @@ export class ChatContainer extends Component {
}

handleSubmit = async (msg) => {
const escapeMap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'\'': '&#x27;',
'`': '&#x60;',
};

const escapeRegex = new RegExp(`(?:${ Object.keys(escapeMap).join('|') })`, 'g');

const escapeHtml = mem(
(string) => string.replace(escapeRegex, (match) => escapeMap[match]),
);

const parse = (plainText) =>
[{ plain: plainText }]
.map(({ plain, html }) => (plain ? escapeHtml(plain) : html || ''))
.join('');

if (msg.trim() === '') {
return;
}
msg = sanitize(msg);

msg = parse(msg);

await this.grantUser();
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5689,11 +5689,6 @@ domhandler@^2.3.0:
dependencies:
domelementtype "1"

dompurify@^2.2.6:
version "2.2.6"
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.2.6.tgz#54945dc5c0b45ce5ae228705777e8e59d7b2edc4"
integrity sha512-7b7ZArhhH0SP6W2R9cqK6RjaU82FZ2UPM7RO8qN1b1wyvC/NY1FNWcX1Pu00fFOAnzEORtwXe4bPaClg6pUybQ==

domutils@1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf"
Expand Down

0 comments on commit 8da8b8b

Please sign in to comment.