Skip to content

Commit

Permalink
fix: check url/token only if they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda committed Oct 8, 2024
1 parent 6ab0fb8 commit a59de04
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 36 deletions.
17 changes: 7 additions & 10 deletions platforms/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 8 additions & 11 deletions platforms/fastly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down
27 changes: 12 additions & 15 deletions platforms/nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down

0 comments on commit a59de04

Please sign in to comment.