Skip to content

Commit 8a9711d

Browse files
committed
Update url-file resolution on CPO to match pyret-lang
See brownplt/pyret-lang@2f2a3ba
1 parent e9c5429 commit 8a9711d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/web/js/cpo-main.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@
150150
// NOTE(joe): this function just allocates a closure, so it's stack-safe
151151
var onCompile = gmf(cpo, "make-on-compile").app(runtime.makeFunction(saveGDriveCachedFile, "save-gdrive-cached-file"));
152152

153+
function maybeAppendSlash(s) {
154+
if(s.endsWith("/")) { return s; }
155+
return s + "/";
156+
}
157+
158+
function urlResolve(path, base) {
159+
return new URL(path, base).href;
160+
}
161+
153162
// NOTE(joe/ben): this function _used_ to be trivially stack safe, but files
154163
// need to resolve their absolute path to calculate their URI, which
155164
// requires an RPC, so this function is no-longer trivially flat
@@ -198,7 +207,7 @@
198207
return arr[0];
199208
}
200209
else if (protocol === "url-file") {
201-
return arr[0] + "/" + arr[1];
210+
return urlResolve(arr[1], maybeAppendSlash(arr[0]));
202211
}
203212
else {
204213
console.error("Unknown import: ", dependency);
@@ -256,7 +265,7 @@
256265
return runtime.getField(runtime.getField(urlLoc, "values"), "url-locator").app(arr[0], replGlobals);
257266
}
258267
else if (protocol === "url-file") {
259-
const fullUrl = arr[0] + "/" + arr[1];
268+
const fullUrl = urlResolve(arr[1], maybeAppendSlash(arr[0]));
260269
switch(urlFileMode) {
261270
case "all-remote":
262271
fetch(fullUrl).then(async (response) => {

0 commit comments

Comments
 (0)