fix(v2): make correct internal link check (#2424)

This commit is contained in:
Alexey Pyltsyn 2020-03-18 18:14:39 +03:00 committed by GitHub
parent 6a089ce75c
commit 2fd50f9c33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,30 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import isInternalUrl from '../isInternalUrl';
describe('isInternalUrl', () => {
test('should be true for root relative links', () => {
expect(isInternalUrl('/foo/bar')).toBeTruthy();
});
test('should be true for relative links', () => {
expect(isInternalUrl('foo/bar')).toBeTruthy();
});
test('should be false for HTTP links', () => {
expect(isInternalUrl('http://foo.com')).toBeFalsy();
});
test('should be false for HTTPS links', () => {
expect(isInternalUrl('https://foo.com')).toBeFalsy();
});
test('should be false for whatever protocol links', () => {
expect(isInternalUrl('//foo.com')).toBeFalsy();
});
});

View File

@ -6,5 +6,5 @@
*/
export default function isInternalUrl(url) {
return /^\/(?!\/)/.test(url);
return /^(https?:|\/\/)/.test(url) === false;
}