From 943af3cd6f1cedfe14b4f60668be32d89b78c52b Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 9 Oct 2025 13:23:28 +0100 Subject: [PATCH] Use path.resolve for resolving paths (#28905) GitOrigin-RevId: 8f549b410ebf35e330a472fd4de1e3343747794e --- package-lock.json | 1 + .../frontend/js/infrastructure/project-snapshot.ts | 11 ++++++----- services/web/package.json | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index b06ada26c6..3a1b180695 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52822,6 +52822,7 @@ "nock": "^13.5.6", "nvd3": "^1.8.6", "p-reflect": "^3.1.0", + "path-browserify": "^1.0.1", "pdfjs-dist": "5.1.91", "pirates": "^4.0.1", "postcss": "^8.4.31", diff --git a/services/web/frontend/js/infrastructure/project-snapshot.ts b/services/web/frontend/js/infrastructure/project-snapshot.ts index 6cd0b20982..0b564cc12b 100644 --- a/services/web/frontend/js/infrastructure/project-snapshot.ts +++ b/services/web/frontend/js/infrastructure/project-snapshot.ts @@ -2,6 +2,7 @@ import pLimit from 'p-limit' import { Change, Chunk, Snapshot, File } from 'overleaf-editor-core' import { RawChange, RawChunk } from 'overleaf-editor-core/lib/types' import { FetchError, getJSON, postJSON } from '@/infrastructure/fetch-json' +import path from 'path-browserify' const DOWNLOAD_BLOBS_CONCURRENCY = 10 @@ -101,21 +102,21 @@ export class ProjectSnapshot { const snapshotPaths = new Set(this.snapshot.getFilePathnames()) - const baseURLs = [ + const basePaths = [ // relative to the root of the compile directory - new URL('https://overleaf.invalid'), + '/', ] if (currentPath !== '/') { // relative to the current directory - baseURLs.push(new URL(currentPath, 'https://overleaf.invalid')) + basePaths.push(currentPath) } const extensionsToTest = ['', ...extensions] - for (const baseURL of baseURLs) { + for (const basePath of basePaths) { for (const extension of extensionsToTest) { - const { pathname } = new URL(`${filePath}${extension}`, baseURL) + const pathname = path.resolve(basePath, `${filePath}${extension}`) const snapshotPath = pathname.substring(1) // remove leading slash if (snapshotPaths.has(snapshotPath)) { return snapshotPath diff --git a/services/web/package.json b/services/web/package.json index efaaa1fe3d..e64ed6204e 100644 --- a/services/web/package.json +++ b/services/web/package.json @@ -351,6 +351,7 @@ "mock-fs": "^5.1.2", "nock": "^13.5.6", "nvd3": "^1.8.6", + "path-browserify": "^1.0.1", "p-reflect": "^3.1.0", "pdfjs-dist": "5.1.91", "pirates": "^4.0.1",