mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
test: valid-host
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { isValidHost } from '@/utils/valid-host';
|
||||
|
||||
describe('valid-host', () => {
|
||||
it('validate hostname', () => {
|
||||
expect(isValidHost()).toBe(false);
|
||||
expect(isValidHost('')).toBe(false);
|
||||
expect(isValidHost('subd0main')).toBe(true);
|
||||
expect(isValidHost('-subd0main')).toBe(false);
|
||||
expect(isValidHost('sub-d0main')).toBe(true);
|
||||
expect(isValidHost('subd0main-')).toBe(false);
|
||||
expect(isValidHost('sub.d0main')).toBe(false);
|
||||
expect(isValidHost('sub-.d0main')).toBe(false);
|
||||
expect(isValidHost('s')).toBe(true);
|
||||
expect(isValidHost('-')).toBe(false);
|
||||
expect(isValidHost('0')).toBe(true);
|
||||
expect(isValidHost('s-')).toBe(false);
|
||||
expect(isValidHost('s-u')).toBe(true);
|
||||
expect(isValidHost('su')).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@
|
||||
* @param {String} hostname sub-domain
|
||||
* @returns {Boolean} true if valid
|
||||
*/
|
||||
const isValidHost = (hostname) => {
|
||||
const isValidHost = (hostname?: string) => {
|
||||
if (typeof hostname !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user