diff --git a/src/components/message/Message.tsx b/src/components/message/Message.tsx index 79cf8c8d..38ab79c0 100644 --- a/src/components/message/Message.tsx +++ b/src/components/message/Message.tsx @@ -1,6 +1,5 @@ import React, { FC, useState } from 'react' import { Message as MessageType } from '../../api/Message' -import { replaceMagic } from '../../lib/replaceLinksHelper' import MessageModalDelete from './MessageModalDelete' import MessageMap from './MessageMap' import { Ticker } from '../../api/Ticker' @@ -32,7 +31,7 @@ const Message: FC = ({ message, ticker }) => { setDeleteModalOpen(false)} open={deleteModalOpen} />

'), }} style={{ paddingRight: theme.spacing(6) }} /> diff --git a/src/lib/replaceLinksHelper.test.ts b/src/lib/replaceLinksHelper.test.ts deleted file mode 100644 index 4ab52375..00000000 --- a/src/lib/replaceLinksHelper.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { replaceMagic } from './replaceLinksHelper' - -describe('helper', function () { - test('replace links', function () { - const text = 'https://www.systemli.org' - - expect(replaceMagic(text)).toBe('www.systemli.org') - }) - - test('replace twitter hashtag', function () { - const text = '#hashtag' - - expect(replaceMagic(text)).toBe('#hashtag') - }) - - test('replace twitter user handle', function () { - const text = '/cc @systemli' - - expect(replaceMagic(text)).toBe('/cc @systemli') - }) - - test('replace email address', function () { - const text = 'sent mail to admin@systemli.org' - - expect(replaceMagic(text)).toBe('sent mail to admin@systemli.org') - }) - - test('replace newline with
tag', function () { - const text = 'newline\nnewtext\r\n' - - expect(replaceMagic(text)).toBe('newline
newtext
') - }) -}) diff --git a/src/lib/replaceLinksHelper.ts b/src/lib/replaceLinksHelper.ts deleted file mode 100644 index 6af9d4b3..00000000 --- a/src/lib/replaceLinksHelper.ts +++ /dev/null @@ -1,12 +0,0 @@ -// FIXME: Might be better to use a library like validator.js -// to catch more cases. -export const replaceMagic = (text: string): string => { - return text - ? text - .replace(/(https?:\/\/([a-zA-Z0-9._\-/]+))/g, '$2') - .replace(/#(\S+)/g, '#$1') - .replace(/ @(\S+)/g, ' @$1') - .replace(/([a-zA-Z0-9_\-.]+@[a-zA-Z0-9_-]+.[a-zA-Z]+)/g, '$1') - .replace(/(?:\r\n|\r|\n)/g, '
') - : '' -}