From a59de0427feb49ffbd10fcc1674ad5ee0bbe3553 Mon Sep 17 00:00:00 2001 From: CahidArda Date: Tue, 8 Oct 2024 16:17:00 +0300 Subject: [PATCH] fix: check url/token only if they exist --- platforms/cloudflare.ts | 17 +++++++---------- platforms/fastly.ts | 19 ++++++++----------- platforms/nodejs.ts | 27 ++++++++++++--------------- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/platforms/cloudflare.ts b/platforms/cloudflare.ts index 19e25f1b..c62e4920 100644 --- a/platforms/cloudflare.ts +++ b/platforms/cloudflare.ts @@ -58,22 +58,19 @@ export class Redis extends core.Redis { console.warn( `[Upstash Redis] The 'url' property is missing or undefined in your Redis config.` ); - } - - if (!config.token) { + } else if (config.url.startsWith(" ") || config.url.endsWith(" ") || /\r|\n/.test(config.url)) { console.warn( - `[Upstash Redis] The 'token' property is missing or undefined in your Redis config.` + "[Upstash Redis] The redis url contains whitespace or newline, which can cause errors!" ); } - if (config.url!.startsWith(" ") || config.url!.endsWith(" ") || /\r|\n/.test(config.url!)) { + if (!config.token) { console.warn( - "[Upstash Redis] The redis url contains whitespace or newline, which can cause errors!" + `[Upstash Redis] The 'token' property is missing or undefined in your Redis config.` ); - } - if ( - config.token!.startsWith(" ") || - config.token!.endsWith(" ") || + } else if ( + config.token.startsWith(" ") || + config.token.endsWith(" ") || /\r|\n/.test(config.token!) ) { console.warn( diff --git a/platforms/fastly.ts b/platforms/fastly.ts index 279e4577..59435174 100644 --- a/platforms/fastly.ts +++ b/platforms/fastly.ts @@ -56,23 +56,20 @@ export class Redis extends core.Redis { console.warn( `[Upstash Redis] The 'url' property is missing or undefined in your Redis config.` ); - } - - if (!config.token) { + } else if (config.url.startsWith(" ") || config.url.endsWith(" ") || /\r|\n/.test(config.url)) { console.warn( - `[Upstash Redis] The 'token' property is missing or undefined in your Redis config.` + "[Upstash Redis] The redis url contains whitespace or newline, which can cause errors!" ); } - if (config.url!.startsWith(" ") || config.url!.endsWith(" ") || /\r|\n/.test(config.url!)) { + if (!config.token) { console.warn( - "[Upstash Redis] The redis url contains whitespace or newline, which can cause errors!" + `[Upstash Redis] The 'token' property is missing or undefined in your Redis config.` ); - } - if ( - config.token!.startsWith(" ") || - config.token!.endsWith(" ") || - /\r|\n/.test(config.token!) + } else if ( + config.token.startsWith(" ") || + config.token.endsWith(" ") || + /\r|\n/.test(config.token) ) { console.warn( "[Upstash Redis] The redis token contains whitespace or newline, which can cause errors!" diff --git a/platforms/nodejs.ts b/platforms/nodejs.ts index 3e3b1840..1387d726 100644 --- a/platforms/nodejs.ts +++ b/platforms/nodejs.ts @@ -105,27 +105,24 @@ export class Redis extends core.Redis { console.warn( `[Upstash Redis] The 'url' property is missing or undefined in your Redis config.` ); - } - - if (!configOrRequester.token) { + } else if ( + configOrRequester.url.startsWith(" ") || + configOrRequester.url.endsWith(" ") || + /\r|\n/.test(configOrRequester.url) + ) { console.warn( - `[Upstash Redis] The 'token' property is missing or undefined in your Redis config.` + "[Upstash Redis] The redis url contains whitespace or newline, which can cause errors!" ); } - if ( - configOrRequester.url!.startsWith(" ") || - configOrRequester.url!.endsWith(" ") || - /\r|\n/.test(configOrRequester.url!) - ) { + if (!configOrRequester.token) { console.warn( - "[Upstash Redis] The redis url contains whitespace or newline, which can cause errors!" + `[Upstash Redis] The 'token' property is missing or undefined in your Redis config.` ); - } - if ( - configOrRequester.token!.startsWith(" ") || - configOrRequester.token!.endsWith(" ") || - /\r|\n/.test(configOrRequester.token!) + } else if ( + configOrRequester.token.startsWith(" ") || + configOrRequester.token.endsWith(" ") || + /\r|\n/.test(configOrRequester.token) ) { console.warn( "[Upstash Redis] The redis token contains whitespace or newline, which can cause errors!"