Remove unused code; move signal.js to js/modules for eslint
(noticed as I was doing this that signal.js doesn't get eslint coverage)
This commit is contained in:
parent
496e0499c4
commit
34f423b52c
7 changed files with 35 additions and 196 deletions
12
js/modules/link_text.d.ts
vendored
12
js/modules/link_text.d.ts
vendored
|
@ -1,12 +0,0 @@
|
||||||
declare namespace LinkText {
|
|
||||||
type Attributes = {
|
|
||||||
[key: string]: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
declare function linkText(
|
|
||||||
value: string,
|
|
||||||
attributes: LinkText.Attributes
|
|
||||||
): string;
|
|
||||||
|
|
||||||
export = linkText;
|
|
|
@ -1,39 +0,0 @@
|
||||||
// Fork of https://github.com/uiureo/link-text with HTML escaping disabled as we leverage
|
|
||||||
// jQuery’s escaping mechanism:
|
|
||||||
|
|
||||||
const linkify = require('linkify-it')();
|
|
||||||
|
|
||||||
function createLink(url, text, attrs = {}) {
|
|
||||||
const html = [];
|
|
||||||
html.push('<a ');
|
|
||||||
html.push(`href="${url}"`);
|
|
||||||
Object.keys(attrs).forEach(key => {
|
|
||||||
html.push(` ${key}="${attrs[key]}"`);
|
|
||||||
});
|
|
||||||
html.push('>');
|
|
||||||
html.push(decodeURIComponent(text));
|
|
||||||
html.push('</a>');
|
|
||||||
|
|
||||||
return html.join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (text, attrs = {}) => {
|
|
||||||
const matchData = linkify.match(text) || [];
|
|
||||||
|
|
||||||
const result = [];
|
|
||||||
let last = 0;
|
|
||||||
|
|
||||||
matchData.forEach(match => {
|
|
||||||
if (last < match.index) {
|
|
||||||
result.push(text.slice(last, match.index));
|
|
||||||
}
|
|
||||||
|
|
||||||
result.push(createLink(match.url, match.text, attrs));
|
|
||||||
|
|
||||||
last = match.lastIndex;
|
|
||||||
});
|
|
||||||
|
|
||||||
result.push(text.slice(last));
|
|
||||||
|
|
||||||
return result.join('');
|
|
||||||
};
|
|
|
@ -1,60 +1,59 @@
|
||||||
// The idea with this file is to make it webpackable for the style guide
|
// The idea with this file is to make it webpackable for the style guide
|
||||||
|
|
||||||
const Backbone = require('../ts/backbone');
|
const Backbone = require('../../ts/backbone');
|
||||||
const Crypto = require('./modules/crypto');
|
const Crypto = require('./crypto');
|
||||||
const Database = require('./modules/database');
|
const Database = require('./database');
|
||||||
const Emoji = require('../ts/util/emoji');
|
const Emoji = require('../../ts/util/emoji');
|
||||||
const HTML = require('../ts/html');
|
const Message = require('./types/message');
|
||||||
const Message = require('./modules/types/message');
|
const Notifications = require('../../ts/notifications');
|
||||||
const Notifications = require('../ts/notifications');
|
const OS = require('../../ts/OS');
|
||||||
const OS = require('../ts/OS');
|
const Settings = require('./settings');
|
||||||
const Settings = require('./modules/settings');
|
const Startup = require('./startup');
|
||||||
const Startup = require('./modules/startup');
|
const Util = require('../../ts/util');
|
||||||
const Util = require('../ts/util');
|
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
const {
|
const {
|
||||||
ContactDetail,
|
ContactDetail,
|
||||||
} = require('../ts/components/conversation/ContactDetail');
|
} = require('../../ts/components/conversation/ContactDetail');
|
||||||
const { ContactName } = require('../ts/components/conversation/ContactName');
|
const { ContactName } = require('../../ts/components/conversation/ContactName');
|
||||||
const {
|
const {
|
||||||
ConversationTitle,
|
ConversationTitle,
|
||||||
} = require('../ts/components/conversation/ConversationTitle');
|
} = require('../../ts/components/conversation/ConversationTitle');
|
||||||
const {
|
const {
|
||||||
EmbeddedContact,
|
EmbeddedContact,
|
||||||
} = require('../ts/components/conversation/EmbeddedContact');
|
} = require('../../ts/components/conversation/EmbeddedContact');
|
||||||
const { Emojify } = require('../ts/components/conversation/Emojify');
|
const { Emojify } = require('../../ts/components/conversation/Emojify');
|
||||||
const { Lightbox } = require('../ts/components/Lightbox');
|
const { Lightbox } = require('../../ts/components/Lightbox');
|
||||||
const { LightboxGallery } = require('../ts/components/LightboxGallery');
|
const { LightboxGallery } = require('../../ts/components/LightboxGallery');
|
||||||
const {
|
const {
|
||||||
MediaGallery,
|
MediaGallery,
|
||||||
} = require('../ts/components/conversation/media-gallery/MediaGallery');
|
} = require('../../ts/components/conversation/media-gallery/MediaGallery');
|
||||||
const { MessageBody } = require('../ts/components/conversation/MessageBody');
|
const { MessageBody } = require('../../ts/components/conversation/MessageBody');
|
||||||
const { Quote } = require('../ts/components/conversation/Quote');
|
const { Quote } = require('../../ts/components/conversation/Quote');
|
||||||
|
|
||||||
// Migrations
|
// Migrations
|
||||||
const {
|
const {
|
||||||
getPlaceholderMigrations,
|
getPlaceholderMigrations,
|
||||||
} = require('./modules/migrations/get_placeholder_migrations');
|
} = require('./migrations/get_placeholder_migrations');
|
||||||
|
|
||||||
const Migrations0DatabaseWithAttachmentData = require('./modules/migrations/migrations_0_database_with_attachment_data');
|
const Migrations0DatabaseWithAttachmentData = require('./migrations/migrations_0_database_with_attachment_data');
|
||||||
const Migrations1DatabaseWithoutAttachmentData = require('./modules/migrations/migrations_1_database_without_attachment_data');
|
const Migrations1DatabaseWithoutAttachmentData = require('./migrations/migrations_1_database_without_attachment_data');
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
const AttachmentType = require('./modules/types/attachment');
|
const AttachmentType = require('./types/attachment');
|
||||||
const Contact = require('../ts/types/Contact');
|
const Contact = require('../../ts/types/Contact');
|
||||||
const Conversation = require('../ts/types/Conversation');
|
const Conversation = require('../../ts/types/Conversation');
|
||||||
const Errors = require('./modules/types/errors');
|
const Errors = require('./types/errors');
|
||||||
const MediaGalleryMessage = require('../ts/components/conversation/media-gallery/types/Message');
|
const MediaGalleryMessage = require('../../ts/components/conversation/media-gallery/types/Message');
|
||||||
const MIME = require('../ts/types/MIME');
|
const MIME = require('../../ts/types/MIME');
|
||||||
const SettingsType = require('../ts/types/Settings');
|
const SettingsType = require('../../ts/types/Settings');
|
||||||
|
|
||||||
// Views
|
// Views
|
||||||
const Initialization = require('./modules/views/initialization');
|
const Initialization = require('./views/initialization');
|
||||||
|
|
||||||
// Workflow
|
// Workflow
|
||||||
const { IdleDetector } = require('./modules/idle_detector');
|
const { IdleDetector } = require('./idle_detector');
|
||||||
const MessageDataMigrator = require('./modules/messages_data_migrator');
|
const MessageDataMigrator = require('./messages_data_migrator');
|
||||||
|
|
||||||
exports.setup = (options = {}) => {
|
exports.setup = (options = {}) => {
|
||||||
const { Attachments, userDataPath, getRegionCode } = options;
|
const { Attachments, userDataPath, getRegionCode } = options;
|
||||||
|
@ -127,7 +126,6 @@ exports.setup = (options = {}) => {
|
||||||
Crypto,
|
Crypto,
|
||||||
Database,
|
Database,
|
||||||
Emoji,
|
Emoji,
|
||||||
HTML,
|
|
||||||
Migrations,
|
Migrations,
|
||||||
Notifications,
|
Notifications,
|
||||||
OS,
|
OS,
|
|
@ -113,7 +113,7 @@ window.React = require('react');
|
||||||
window.ReactDOM = require('react-dom');
|
window.ReactDOM = require('react-dom');
|
||||||
window.moment = require('moment');
|
window.moment = require('moment');
|
||||||
|
|
||||||
const Signal = require('./js/signal');
|
const Signal = require('./js/modules/signal');
|
||||||
const i18n = require('./js/modules/i18n');
|
const i18n = require('./js/modules/i18n');
|
||||||
const Attachments = require('./app/attachments');
|
const Attachments = require('./app/attachments');
|
||||||
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
// tslint:disable-next-line: match-default-export-name
|
|
||||||
import linkTextInternal from '../../js/modules/link_text';
|
|
||||||
|
|
||||||
export const linkText = (value: string): string =>
|
|
||||||
linkTextInternal(value, { target: '_blank' });
|
|
||||||
|
|
||||||
export const replaceLineBreaks = (value: string): string =>
|
|
||||||
value.replace(/\r?\n/g, '<br>');
|
|
||||||
|
|
||||||
// NOTE: How can we use `lodash/fp` `compose` with type checking?
|
|
||||||
export const render = (value: string): string =>
|
|
||||||
replaceLineBreaks(linkText(value));
|
|
|
@ -15,7 +15,7 @@ export { ConversationContext } from './ConversationContext';
|
||||||
export { BackboneWrapper } from '../components/utility/BackboneWrapper';
|
export { BackboneWrapper } from '../components/utility/BackboneWrapper';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import * as Signal from '../../js/signal';
|
import * as Signal from '../../js/modules/signal';
|
||||||
import { SignalService } from '../protobuf';
|
import { SignalService } from '../protobuf';
|
||||||
|
|
||||||
// TypeScript wants two things when you import:
|
// TypeScript wants two things when you import:
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
import { assert } from 'chai';
|
|
||||||
|
|
||||||
import * as HTML from '../../html';
|
|
||||||
|
|
||||||
interface Test {
|
|
||||||
input: string;
|
|
||||||
name: string;
|
|
||||||
output?: string;
|
|
||||||
outputHref?: string;
|
|
||||||
outputLabel?: string;
|
|
||||||
postText?: string;
|
|
||||||
preText?: string;
|
|
||||||
skipped?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('HTML', () => {
|
|
||||||
describe('linkText', () => {
|
|
||||||
const TESTS: Array<Test> = [
|
|
||||||
{
|
|
||||||
name: 'square brackets',
|
|
||||||
input: 'https://www.example.com/test.html?foo=bar&baz[qux]=quux',
|
|
||||||
output: 'https://www.example.com/test.html?foo=bar&baz[qux]=quux',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Chinese characters',
|
|
||||||
input: 'https://zh.wikipedia.org/zh-hans/信号',
|
|
||||||
output: 'https://zh.wikipedia.org/zh-hans/信号',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Cyrillic characters',
|
|
||||||
input: 'https://ru.wikipedia.org/wiki/Сигнал',
|
|
||||||
output: 'https://ru.wikipedia.org/wiki/Сигнал',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
skipped: true,
|
|
||||||
name: 'trailing exclamation points',
|
|
||||||
input: 'https://en.wikipedia.org/wiki/Mother!',
|
|
||||||
output: 'https://en.wikipedia.org/wiki/Mother!',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'single quotes',
|
|
||||||
input: "https://www.example.com/this-couldn't-be-true",
|
|
||||||
output: "https://www.example.com/this-couldn't-be-true",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'special characters before URL begins',
|
|
||||||
preText: 'wink ;)',
|
|
||||||
input: 'https://www.youtube.com/watch?v=oHg5SJYRHA0',
|
|
||||||
output: 'https://www.youtube.com/watch?v=oHg5SJYRHA0',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'URLs without protocols',
|
|
||||||
input: 'github.com',
|
|
||||||
// tslint:disable-next-line:no-http-string
|
|
||||||
outputHref: 'http://github.com',
|
|
||||||
outputLabel: 'github.com',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
TESTS.forEach(test => {
|
|
||||||
(test.skipped ? it.skip : it)(`should handle ${test.name}`, () => {
|
|
||||||
const preText = test.preText || 'Hello ';
|
|
||||||
const postText = test.postText || ' World!';
|
|
||||||
const input: string = `${preText}${test.input}${postText}`;
|
|
||||||
const expected: string = [
|
|
||||||
preText,
|
|
||||||
`<a href="${test.outputHref || test.output}" target="_blank">`,
|
|
||||||
test.outputLabel || test.output,
|
|
||||||
'</a>',
|
|
||||||
postText,
|
|
||||||
].join('');
|
|
||||||
|
|
||||||
const actual = HTML.linkText(input);
|
|
||||||
assert.equal(actual, expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('render', () => {
|
|
||||||
it('should preserve line breaks', () => {
|
|
||||||
const input: string = 'Hello\n\n\nWorld!';
|
|
||||||
const expected: string = 'Hello<br><br><br>World!';
|
|
||||||
|
|
||||||
const actual = HTML.render(input);
|
|
||||||
assert.equal(actual, expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not escape HTML', () => {
|
|
||||||
const input: string = "Hello\n<script>alert('evil');</script>World!";
|
|
||||||
const expected: string = "Hello<br><script>alert('evil');</script>World!";
|
|
||||||
|
|
||||||
const actual = HTML.render(input);
|
|
||||||
assert.equal(actual, expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Add table
Add a link
Reference in a new issue