Skip to content

Commit

Permalink
error if server: shiny document references resources in the parent di…
Browse files Browse the repository at this point in the history
…rectory
  • Loading branch information
jjallaire committed Oct 14, 2023
1 parent ec07856 commit 87b3443
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/execute/jupyter/jupyter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import {
import { jupyterCapabilities } from "../../core/jupyter/capabilities.ts";
import { runExternalPreviewServer } from "../../preview/preview-server.ts";
import { onCleanup } from "../../core/cleanup.ts";
import { basename } from "https://deno.land/[email protected]/path/win32.ts";

export const jupyterEngine: ExecutionEngine = {
name: kJupyterEngine,
Expand Down Expand Up @@ -522,13 +523,25 @@ export const jupyterEngine: ExecutionEngine = {
.map((resource) => relative(dir, resource));
const appScript = join(dir, `${stem}-app.py`);
if (existsSync(appScript)) {
const staticAssets = [
inputFilesDir(file.input),
...extraResources,
];
// compute static assets
const staticAssets = [inputFilesDir(file.input), ...extraResources];

// check for (illegal) parent dir assets
const parentDirAssets = staticAssets.filter((asset) =>
asset.startsWith("..")
);
if (parentDirAssets.length > 0) {
error(
`References to files in parent directories found in document with server: shiny ` +
`(${basename(file.input)}): ${
JSON.stringify(parentDirAssets)
}. All resource files referenced ` +
`by Shiny documents must exist in the same directory as the source file.`,
);
throw new Error();
}

// In the app.py file, replace the placeholder with the list of static
// assets.
// In the app.py file, replace the placeholder with the list of static assets.
let appContents = Deno.readTextFileSync(appScript);
appContents = appContents.replace(
"##STATIC_ASSETS_PLACEHOLDER##",
Expand Down

0 comments on commit 87b3443

Please sign in to comment.