Remove IP addresses from "sneaky" link detection
This commit is contained in:
parent
63b2644cb4
commit
693deaebe8
2 changed files with 13 additions and 21 deletions
|
@ -1,7 +1,6 @@
|
|||
/* global URL */
|
||||
|
||||
const { isNumber, compact, isEmpty } = require('lodash');
|
||||
const { isIP } = require('net');
|
||||
const nodeUrl = require('url');
|
||||
const LinkifyIt = require('linkify-it');
|
||||
|
||||
|
@ -99,11 +98,6 @@ function isLinkSneaky(link) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Domain cannot be an IP address.
|
||||
if (isIP(domain)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// There must be at least 2 domain labels, and none of them can be empty.
|
||||
const labels = domain.split('.');
|
||||
if (labels.length < 2 || labels.some(isEmpty)) {
|
||||
|
|
|
@ -120,6 +120,19 @@ describe('Link previews', () => {
|
|||
assert.strictEqual(actual, false);
|
||||
});
|
||||
|
||||
it('returns false for IPv4 addresses', () => {
|
||||
assert.isFalse(isLinkSneaky('https://127.0.0.1/path'));
|
||||
});
|
||||
|
||||
// It's possible that this should return `false` but we'd need to add special logic
|
||||
// for it.
|
||||
it('returns true for IPv6 addresses', () => {
|
||||
assert.isTrue(
|
||||
isLinkSneaky('https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]/path')
|
||||
);
|
||||
assert.isTrue(isLinkSneaky('https://[::]/path'));
|
||||
});
|
||||
|
||||
it('returns true for Latin + Cyrillic domain', () => {
|
||||
const link = 'https://www.aмazon.com';
|
||||
const actual = isLinkSneaky(link);
|
||||
|
@ -175,21 +188,6 @@ describe('Link previews', () => {
|
|||
assert.isTrue(isLinkSneaky('https://localhost:3000'));
|
||||
});
|
||||
|
||||
it('returns true if the domain is an IPv4 address', () => {
|
||||
assert.isTrue(isLinkSneaky('https://127.0.0.1/path'));
|
||||
assert.isTrue(isLinkSneaky('https://127.0.0.1:1234/path'));
|
||||
assert.isTrue(isLinkSneaky('https://13.249.138.50/path'));
|
||||
assert.isTrue(isLinkSneaky('https://13.249.138.50:1234/path'));
|
||||
});
|
||||
|
||||
it('returns true if the domain is an IPv6 address', () => {
|
||||
assert.isTrue(
|
||||
isLinkSneaky('https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]/path')
|
||||
);
|
||||
assert.isTrue(isLinkSneaky('https://[2001::]/path'));
|
||||
assert.isTrue(isLinkSneaky('https://[::]/path'));
|
||||
});
|
||||
|
||||
it('returns true if the domain has any empty labels', () => {
|
||||
assert.isTrue(isLinkSneaky('https://example.'));
|
||||
assert.isTrue(isLinkSneaky('https://example.com.'));
|
||||
|
|
Loading…
Add table
Reference in a new issue