diff --git a/pxtsim/simdriver.ts b/pxtsim/simdriver.ts index f3f07a48661e..a2946a98b870 100644 --- a/pxtsim/simdriver.ts +++ b/pxtsim/simdriver.ts @@ -160,14 +160,11 @@ namespace pxsim { } else { const simUrl = this.getSimUrl(); // Ensure we preserve upload target path (/app/---simulator) - let simPath = simUrl.pathname.replace(/---?.*/, ""); - // Remove leading and trailing slashes - simPath = simPath.replace(/^\/+|\/+$/, ""); + const simPath = simUrl.pathname.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(); + const simxPath = [simPath, "simx", key, "-", simx.index].join("/"); + // Create the fully-qualified URL, preserving the origin by removing all leading slashes + simx.url = new URL(simxPath.replace(/^\/+/, ""), simUrl.origin).toString(); } // Add the origin to the allowed origins