diff --git a/js/modules/link_previews.js b/js/modules/link_previews.js index 2eefb9ddf7..a92312a2b3 100644 --- a/js/modules/link_previews.js +++ b/js/modules/link_previews.js @@ -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)) { diff --git a/test/modules/link_previews_test.js b/test/modules/link_previews_test.js index 2440f3696c..8ee6e72d00 100644 --- a/test/modules/link_previews_test.js +++ b/test/modules/link_previews_test.js @@ -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.'));