From 556ddc319242aafef51bae9301423ecf8701a3af Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 25 Aug 2017 18:36:49 +0200 Subject: Upgrade common server dependencies --- server/helpers/custom-validators/pods.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'server/helpers/custom-validators/pods.ts') diff --git a/server/helpers/custom-validators/pods.ts b/server/helpers/custom-validators/pods.ts index 0519def52..f2ca520c0 100644 --- a/server/helpers/custom-validators/pods.ts +++ b/server/helpers/custom-validators/pods.ts @@ -1,9 +1,20 @@ 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[]) { @@ -21,11 +32,9 @@ export { isHostValid } -declare global { - namespace ExpressValidator { - export interface Validator { - isEachUniqueHostValid - isHostValid - } +declare module 'express-validator' { + export interface Validator { + isEachUniqueHostValid + isHostValid } } -- cgit v1.2.3