diff --git a/cli/server.ts b/cli/server.ts index a01f12accbc7..8a269125d586 100644 --- a/cli/server.ts +++ b/cli/server.ts @@ -825,7 +825,7 @@ function certificateTestAsync(): Promise { // use http://localhost:3232/45912-50568-62072-42379 for testing function scriptPageTestAsync(id: string) { - return Cloud.privateGetAsync(id) + return Cloud.privateGetAsync(pxt.Cloud.parseScriptId(id)) .then((info: Cloud.JsonScript) => { // if running against old cloud, infer 'thumb' field // can be removed after new cloud deployment @@ -854,7 +854,7 @@ function scriptPageTestAsync(id: string) { filepath: "/" + id }) return html - }) + }); } // use http://localhost:3232/pkg/microsoft/pxt-neopixel for testing @@ -1140,9 +1140,10 @@ export function serveAsync(options: ServeOptions) { return } - if (/^\/(\d\d\d\d[\d-]+)$/.test(pathname)) { - scriptPageTestAsync(pathname.slice(1)) + if (!!pxt.Cloud.parseScriptId(pathname)) { + scriptPageTestAsync(pathname) .then(sendHtml) + .catch(() => error(404, "Script not found")); return } diff --git a/pxtlib/emitter/cloud.ts b/pxtlib/emitter/cloud.ts index 58718dd184de..a5b5e38c34ce 100644 --- a/pxtlib/emitter/cloud.ts +++ b/pxtlib/emitter/cloud.ts @@ -251,7 +251,7 @@ namespace pxt.Cloud { const domainCheck = `(?:(?:https:\/\/)?(?:${domains.join('|')})\/)`; const versionRefCheck = "(?:v[0-9]+\/)"; const oembedCheck = "api\/oembed\\?url=.*%2F([^&#]*)&.*"; - const sharePageCheck = "([a-z0-9\\-_]+)(?:[#?&].*)?"; + const sharePageCheck = "\/?([a-z0-9\\-_]+)(?:[#?&].*)?"; const scriptIdCheck = `^${domainCheck}?${versionRefCheck}?(?:(?:${oembedCheck})|(?:${sharePageCheck}))$`; const m = new RegExp(scriptIdCheck, 'i').exec(uri.trim()); const scriptid = m?.[1] /** oembed res **/ || m?.[2] /** share page res **/;