From c9ccd214ea18d5ac833a916f147e1931b82be9f0 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 22 Nov 2021 09:38:45 -0800 Subject: [PATCH] fix: normalize module path passed to runfiles helper for robustness --- internal/runfiles/index.js | 9 +++++++++ packages/runfiles/runfiles.ts | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/internal/runfiles/index.js b/internal/runfiles/index.js index a700fc21dd..ee37219d30 100644 --- a/internal/runfiles/index.js +++ b/internal/runfiles/index.js @@ -130,6 +130,9 @@ class Runfiles { } /** Resolves the given module path. */ resolve(modulePath) { + // Normalize path by converting to forward slashes and removing all trailing + // forward slashes + modulePath = modulePath.replace(/\\/g, '/').replace(/\/+$/g, ''); if (path__default['default'].isAbsolute(modulePath)) { return modulePath; } @@ -143,6 +146,9 @@ class Runfiles { } /** Resolves the given path relative to the current Bazel workspace. */ resolveWorkspaceRelative(modulePath) { + // Normalize path by converting to forward slashes and removing all trailing + // forward slashes + modulePath = modulePath.replace(/\\/g, '/').replace(/\/+$/g, ''); if (!this.workspace) { throw new Error('workspace could not be determined from the environment; make sure BAZEL_WORKSPACE is set'); } @@ -150,6 +156,9 @@ class Runfiles { } /** Resolves the given path relative to the current Bazel package. */ resolvePackageRelative(modulePath) { + // Normalize path by converting to forward slashes and removing all trailing + // forward slashes + modulePath = modulePath.replace(/\\/g, '/').replace(/\/+$/g, ''); if (!this.workspace) { throw new Error('workspace could not be determined from the environment; make sure BAZEL_WORKSPACE is set'); } diff --git a/packages/runfiles/runfiles.ts b/packages/runfiles/runfiles.ts index 1f86369716..37528d8633 100755 --- a/packages/runfiles/runfiles.ts +++ b/packages/runfiles/runfiles.ts @@ -114,6 +114,9 @@ export class Runfiles { /** Resolves the given module path. */ resolve(modulePath: string) { + // Normalize path by converting to forward slashes and removing all trailing + // forward slashes + modulePath = modulePath.replace(/\\/g, '/').replace(/\/+$/g, '') if (path.isAbsolute(modulePath)) { return modulePath; } @@ -128,6 +131,9 @@ export class Runfiles { /** Resolves the given path relative to the current Bazel workspace. */ resolveWorkspaceRelative(modulePath: string) { + // Normalize path by converting to forward slashes and removing all trailing + // forward slashes + modulePath = modulePath.replace(/\\/g, '/').replace(/\/+$/g, '') if (!this.workspace) { throw new Error( 'workspace could not be determined from the environment; make sure BAZEL_WORKSPACE is set'); @@ -137,6 +143,9 @@ export class Runfiles { /** Resolves the given path relative to the current Bazel package. */ resolvePackageRelative(modulePath: string) { + // Normalize path by converting to forward slashes and removing all trailing + // forward slashes + modulePath = modulePath.replace(/\\/g, '/').replace(/\/+$/g, '') if (!this.workspace) { throw new Error( 'workspace could not be determined from the environment; make sure BAZEL_WORKSPACE is set');