From 2d0e14a3caac773ba6c07520cd81e16d2e1df332 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Fri, 11 Oct 2024 12:13:47 -0700 Subject: [PATCH] fix path formatting issue --- pxtsim/simdriver.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pxtsim/simdriver.ts b/pxtsim/simdriver.ts index edd30cac22af..f3f07a48661e 100644 --- a/pxtsim/simdriver.ts +++ b/pxtsim/simdriver.ts @@ -160,9 +160,13 @@ namespace pxsim { } else { const simUrl = this.getSimUrl(); // Ensure we preserve upload target path (/app/---simulator) - const simPath = simUrl.pathname.replace(/---?.*/, ""); - // Construct the path. The "-" element delineates the extension key from the resource name. - const simxPath = [simPath, "simx", key, "-", simx.index].join("/"); + let simPath = simUrl.pathname.replace(/---?.*/, ""); + // Remove leading and trailing slashes + simPath = simPath.replace(/^\/+|\/+$/, ""); + // Construct the path. The "-" element delineates the extension key from the resource name + let simxPath = [simPath, "simx", key, "-", simx.index].join("/"); + // Append a leading slash to `simxPath` unless it already has one (if `simPath` was an empty string then it will already have a leading slash) + simxPath = simxPath.startsWith("/") ? simxPath : `/${simxPath}`; simx.url = new URL(simxPath, simUrl.origin).toString(); }