bug(ENG-21479): Fix Valkey URL Parsing (#24458)

### What does this PR do?

Fixes https://github.com/oven-sh/bun/issues/24385

### How did you verify your code works?

Confirmed that the test added in the first commit fails on mainline
`bun` and is fixed in this PR.

---------

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
Marko Vejnovic
2025-11-07 21:18:07 -08:00
committed by GitHub
parent de9a38bd11
commit 02b474415d
3 changed files with 84 additions and 7 deletions

11
test/_util/collection.ts Normal file
View File

@@ -0,0 +1,11 @@
/**
* Computes the Cartesian product of multiple arrays.
*
* @param arrays An array of arrays for which to compute the Cartesian product.
* @returns An array containing all combinations of elements from the input arrays.
*/
export function cartesianProduct<T, U>(left: T[], right: U[]): [T, U][] {
return left.flatMap(leftItem =>
right.map(rightItem => [leftItem, rightItem] as [T, U])
);
}

View File

@@ -0,0 +1,37 @@
// https://github.com/oven-sh/bun/issues/24385
// Test for Redis client import regression
import { cartesianProduct } from "_util/collection";
import { expect, test } from "bun:test";
import { bunEnv, bunExe } from "harness";
test.concurrent.each(
cartesianProduct(
["REDIS_URL", "VALKEY_URL"],
[
"localhost:6379",
"redis+tls+unix:///tmp/redis.sock",
"redis+tls://localhost:6379",
"redis+unix:///tmp/redis.sock",
"redis://localhost:6379",
"rediss://localhost:6379",
"valkey://localhost:6379",
],
).map(([k, v]) => ({ key: k, value: v })),
)("Redis loads with $key=$value", async ({ key, value }) => {
const env = { ...bunEnv, [key]: value };
await using proc = Bun.spawn({
// We need to call redis.duplicate() since Bun lazily imports redis.
cmd: [bunExe(), "-e", 'import { redis } from "bun"; const d = redis.duplicate(); console.log("success");'],
env,
stderr: "pipe",
stdout: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect(stderr).not.toContain("Expected url protocol to be one of");
expect(stdout).toContain("success");
expect(exitCode).toBe(0);
});