import * as validator from 'validator'
import { isArray, exists } from './misc'
+import { isTestInstance } from '../core-utils'
function isHostValid (host: string) {
- return exists(host) && validator.isURL(host) && host.split('://').length === 1
+ const isURLOptions = {
+ require_host: true,
+ require_tld: true
+ }
+
+ // We validate 'localhost', so we don't have the top level domain
+ if (isTestInstance()) {
+ isURLOptions.require_tld = false
+ }
+
+ return exists(host) && validator.isURL(host, isURLOptions) && host.split('://').length === 1
}
function isEachUniqueHostValid (hosts: string[]) {
isHostValid
}
-declare global {
- namespace ExpressValidator {
- export interface Validator {
- isEachUniqueHostValid
- isHostValid
- }
+declare module 'express-validator' {
+ export interface Validator {
+ isEachUniqueHostValid
+ isHostValid
}
}