Files
bun.sh/test/js/node/url/pathToFileURL.test.ts
2025-01-31 05:24:57 -08:00

30 lines
903 B
TypeScript

import { test, expect } from "bun:test";
import path from "path";
test("pathToFileURL doesn't leak memory", () => {
expect([path.join(import.meta.dir, "pathToFileURL-leak-fixture.js")]).toRun();
});
test("pathToFileURL escapes special characters", () => {
const cases = [
['\0', '%00'], // '\0' == 0x00
['\t', '%09'], // '\t' == 0x09
['\n', '%0A'], // '\n' == 0x0A
['\r', '%0D'], // '\r' == 0x0D
[' ', '%20'], // ' ' == 0x20
['"', '%22'], // '"' == 0x22
['#', '%23'], // '#' == 0x23
['%', '%25'], // '%' == 0x25
['?', '%3F'], // '?' == 0x3F
['[', '%5B'], // '[' == 0x5B
[']', '%5D'], // ']' == 0x5D
['^', '%5E'], // '^' == 0x5E
['|', '%7C'], // '|' == 0x7C
['~', '%7E'], // '~' == 0x7E
];
for (const [input, expected] of cases) {
expect(Bun.pathToFileURL(`${input}`).toString()).toInclude(expected);
}
});