From 7c8f52a3c6c46042f305cfdd478f39c4d1d1b7ae Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 11 Jan 2025 01:33:42 -0800 Subject: [PATCH] Make file URL parser more robust --- src/core.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index bf05749..b9d324e 100644 --- a/src/core.js +++ b/src/core.js @@ -1,5 +1,6 @@ import { createReadStream } from 'node:fs'; import { mkdir, open } from 'node:fs/promises'; +import { platform } from 'node:os'; import { dirname, normalize } from 'node:path'; import { Readable } from 'node:stream'; /** @import { PathLike } from 'node:fs' */ @@ -185,7 +186,12 @@ export function createCSVWritableStream(path) { fullPath = normalize(new TextDecoder().decode(path)); } else { // Assuming URL - fullPath = normalize(path.pathname.substring(1)); + if (platform() === 'win32' && path.pathname.startsWith('/')) { + fullPath = normalize(decodeURIComponent(path.pathname.substring(1))); + } + else { + fullPath = normalize(decodeURIComponent(path.pathname)); + } } const dir = dirname(fullPath); let handle; -- 2.47.3