mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-26 01:33:02 +00:00
fix(v2): make correct internal link check (#2424)
This commit is contained in:
parent
6a089ce75c
commit
2fd50f9c33
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
@ -6,5 +6,5 @@
|
|||
*/
|
||||
|
||||
export default function isInternalUrl(url) {
|
||||
return /^\/(?!\/)/.test(url);
|
||||
return /^(https?:|\/\/)/.test(url) === false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue