Don't try generating link previews for debuglogs.org
This commit is contained in:
parent
4e48d7792b
commit
efee887135
4 changed files with 30 additions and 21 deletions
|
@ -2212,7 +2212,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
(item: typeof window.WhatIsThis) =>
|
||||
(item.image || item.title) &&
|
||||
urls.includes(item.url) &&
|
||||
LinkPreview.isLinkSafeToPreview(item.url)
|
||||
LinkPreview.shouldPreviewHref(item.url)
|
||||
);
|
||||
if (preview.length < incomingPreview.length) {
|
||||
log.info(
|
||||
|
|
|
@ -5,37 +5,41 @@ import { assert } from 'chai';
|
|||
|
||||
import {
|
||||
findLinks,
|
||||
isLinkSafeToPreview,
|
||||
shouldPreviewHref,
|
||||
isLinkSneaky,
|
||||
} from '../../types/LinkPreview';
|
||||
|
||||
describe('Link previews', () => {
|
||||
describe('#isLinkSafeToPreview', () => {
|
||||
describe('#shouldPreviewHref', () => {
|
||||
it('returns false for invalid URLs', () => {
|
||||
assert.isFalse(isLinkSafeToPreview(''));
|
||||
assert.isFalse(isLinkSafeToPreview('https'));
|
||||
assert.isFalse(isLinkSafeToPreview('https://'));
|
||||
assert.isFalse(isLinkSafeToPreview('https://bad url'));
|
||||
assert.isFalse(isLinkSafeToPreview('example.com'));
|
||||
assert.isFalse(shouldPreviewHref(''));
|
||||
assert.isFalse(shouldPreviewHref('https'));
|
||||
assert.isFalse(shouldPreviewHref('https://'));
|
||||
assert.isFalse(shouldPreviewHref('https://bad url'));
|
||||
assert.isFalse(shouldPreviewHref('example.com'));
|
||||
});
|
||||
|
||||
it('returns false for non-HTTPS URLs', () => {
|
||||
assert.isFalse(isLinkSafeToPreview('http://example.com'));
|
||||
assert.isFalse(isLinkSafeToPreview('ftp://example.com'));
|
||||
assert.isFalse(isLinkSafeToPreview('file://example'));
|
||||
assert.isFalse(shouldPreviewHref('http://example.com'));
|
||||
assert.isFalse(shouldPreviewHref('ftp://example.com'));
|
||||
assert.isFalse(shouldPreviewHref('file://example'));
|
||||
});
|
||||
|
||||
it('returns false if the link is "sneaky"', () => {
|
||||
// See `isLinkSneaky` tests below for more thorough checking.
|
||||
assert.isFalse(isLinkSafeToPreview('https://user:pass@example.com'));
|
||||
assert.isFalse(isLinkSafeToPreview('https://aquí.example'));
|
||||
assert.isFalse(isLinkSafeToPreview('https://aqu%C3%AD.example'));
|
||||
assert.isFalse(shouldPreviewHref('https://user:pass@example.com'));
|
||||
assert.isFalse(shouldPreviewHref('https://aquí.example'));
|
||||
assert.isFalse(shouldPreviewHref('https://aqu%C3%AD.example'));
|
||||
});
|
||||
|
||||
it('returns false for skipped domains', () => {
|
||||
assert.isFalse(shouldPreviewHref('https://debuglogs.org'));
|
||||
});
|
||||
|
||||
it('returns true for "safe" urls', () => {
|
||||
assert.isTrue(isLinkSafeToPreview('https://example.com'));
|
||||
assert.isTrue(shouldPreviewHref('https://example.com'));
|
||||
assert.isTrue(
|
||||
isLinkSafeToPreview('https://example.com/foo/bar?query=string#hash')
|
||||
shouldPreviewHref('https://example.com/foo/bar?query=string#hash')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -28,9 +28,14 @@ export type LinkPreviewWithDomain = {
|
|||
|
||||
const linkify = LinkifyIt();
|
||||
|
||||
export function isLinkSafeToPreview(href: string): boolean {
|
||||
export function shouldPreviewHref(href: string): boolean {
|
||||
const url = maybeParseUrl(href);
|
||||
return Boolean(url && url.protocol === 'https:' && !isLinkSneaky(href));
|
||||
return Boolean(
|
||||
url &&
|
||||
url.protocol === 'https:' &&
|
||||
url.hostname !== 'debuglogs.org' &&
|
||||
!isLinkSneaky(href)
|
||||
);
|
||||
}
|
||||
|
||||
export function isStickerPack(link = ''): boolean {
|
||||
|
|
|
@ -2999,7 +2999,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
|||
|
||||
const link = links.find(
|
||||
item =>
|
||||
LinkPreview.isLinkSafeToPreview(item) &&
|
||||
LinkPreview.shouldPreviewHref(item) &&
|
||||
!this.excludedPreviewUrls.includes(item)
|
||||
);
|
||||
if (!link) {
|
||||
|
@ -3226,7 +3226,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
|||
}
|
||||
|
||||
// This is already checked elsewhere, but we want to be extra-careful.
|
||||
if (!LinkPreview.isLinkSafeToPreview(url)) {
|
||||
if (!LinkPreview.shouldPreviewHref(url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -3241,7 +3241,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
|
|||
const { title, imageHref, description, date } = linkPreviewMetadata;
|
||||
|
||||
let image;
|
||||
if (imageHref && LinkPreview.isLinkSafeToPreview(imageHref)) {
|
||||
if (imageHref && LinkPreview.shouldPreviewHref(imageHref)) {
|
||||
let objectUrl: void | string;
|
||||
try {
|
||||
const fullSizeImage =
|
||||
|
|
Loading…
Reference in a new issue