Skip to content

Commit 8f324fe

Browse files
authored
Bugfix/issue 3163 (#3246)
* bump to latest ojs-runtime. * process url-encoding of binary files correctly. Closes #3163
1 parent 62412d1 commit 8f324fe

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

src/execute/ojs/extract-resources.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ export async function makeSelfContainedResources(
708708
wd: string,
709709
) {
710710
const asDataURL = (
711-
content: string,
711+
content: ArrayBuffer | string,
712712
mimeType: string,
713713
) => {
714714
const b64Src = base64Encode(content);
@@ -758,11 +758,13 @@ export async function makeSelfContainedResources(
758758
...attachments.map(
759759
(f) => {
760760
const resolvedFileName = resolveResourceFilename(f, Deno.cwd());
761+
const mimeType = lookup(resolvedFileName) ||
762+
"application/octet-stream";
761763
return [
762764
f.filename,
763765
asDataURL(
764-
Deno.readTextFileSync(resolvedFileName),
765-
lookup(resolvedFileName)!,
766+
Deno.readFileSync(resolvedFileName).buffer,
767+
mimeType,
766768
),
767769
];
768770
},

src/resources/formats/html/ojs/quarto-ojs-runtime.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @quarto/quarto-ojs-runtime v0.0.14 Copyright 2022 undefined
1+
// @quarto/quarto-ojs-runtime v0.0.15 Copyright 2022 undefined
22
var EOL = {},
33
EOF = {},
44
QUOTE = 34,
@@ -416,6 +416,14 @@ function requirer(resolve) {
416416
return resolve == null ? requireDefault : requireFrom(resolve);
417417
}
418418

419+
function fromEntries(obj) {
420+
const result = {};
421+
for (const [key, value] of obj) {
422+
result[key] = value;
423+
}
424+
return result;
425+
}
426+
419427
async function sqlite(require) {
420428
const [init, dist] = await Promise.all([require(sql.resolve()), require.resolve(sql.resolve("dist/"))]);
421429
return init({locateFile: file => `${dist}${file}`});
@@ -11084,7 +11092,7 @@ var dist = {exports: {}};
1108411092

1108511093
if (!mapValue) return "";
1108611094
return ` const fileAttachments = new Map(${mapValue});
11087-
main.builtin("FileAttachment", runtime.fileAttachments(name => fileAttachments.get(name)));`;
11095+
main.builtin("FileAttachment", runtime.fileAttachments(name => fileAttachments.get(name)));`;
1108811096
}
1108911097

1109011098
function ESMVariables(moduleObject, importMap, params) {
@@ -11110,12 +11118,12 @@ var dist = {exports: {}};
1111011118
if (defineImportMarkdown)
1111111119
src +=
1111211120
` main.variable(observer()).define(
11113-
null,
11114-
["md"],
11115-
md => md\`~~~javascript
11116-
${importString}
11117-
~~~\`
11118-
);` + "\n";
11121+
null,
11122+
["md"],
11123+
md => md\`~~~javascript
11124+
${importString}
11125+
~~~\`
11126+
);` + "\n";
1111911127

1112011128
// name imported notebook define functions
1112111129
const childName = `child${++childJ}`;
@@ -11124,7 +11132,7 @@ var dist = {exports: {}};
1112411132
})${
1112511133
hasInjections ? `.derive(${JSON.stringify(injections)}, main)` : ""
1112611134
};
11127-
${specifiers
11135+
${specifiers
1112811136
.map(
1112911137
specifier =>
1113011138
` main.import("${specifier.name}", "${specifier.alias}", ${childName});`
@@ -11143,8 +11151,8 @@ var dist = {exports: {}};
1114311151
let code = "";
1114411152
if (cell.body.type !== "BlockStatement")
1114511153
code = `{return(
11146-
${bodyText}
11147-
)}`;
11154+
${bodyText}
11155+
)}`;
1114811156
else code = "\n" + bodyText + "\n";
1114911157
const cellReferencesString = cellReferences.length
1115011158
? JSON.stringify(cellReferences) + ", "
@@ -11161,15 +11169,15 @@ var dist = {exports: {}};
1116111169
if (cell.id && cell.id.type === "ViewExpression") {
1116211170
const reference = `"viewof ${cellName}"`;
1116311171
src += ` main.variable(observer(${reference})).define(${reference}, ${cellReferencesString}${cellFunction});
11164-
main.variable(${
11172+
main.variable(${
1116511173
observeViewofValues ? `observer("${cellName}")` : `null`
1116611174
}).define("${cellName}", ["Generators", ${reference}], (G, _) => G.input(_));`;
1116711175
} else if (cell.id && cell.id.type === "MutableExpression") {
1116811176
const initialName = `"initial ${cellName}"`;
1116911177
const mutableName = `"mutable ${cellName}"`;
1117011178
src += ` main.define(${initialName}, ${cellReferencesString}${cellFunction});
11171-
main.variable(observer(${mutableName})).define(${mutableName}, ["Mutable", ${initialName}], (M, _) => new M(_));
11172-
main.variable(${
11179+
main.variable(observer(${mutableName})).define(${mutableName}, ["Mutable", ${initialName}], (M, _) => new M(_));
11180+
main.variable(${
1117311181
observeMutableValues ? `observer("${cellName}")` : `null`
1117411182
}).define("${cellName}", [${mutableName}], _ => _.generator);`;
1117511183
} else {
@@ -11193,19 +11201,19 @@ var dist = {exports: {}};
1119311201
} = params;
1119411202
const { importSrc, importMap } = ESMImports(moduleObject, resolveImportPath);
1119511203
return `${importSrc}export default function define(runtime, observer) {
11196-
const main = runtime.module();
11197-
${ESMAttachments(
11204+
const main = runtime.module();
11205+
${ESMAttachments(
1119811206
moduleObject,
1119911207
resolveFileAttachments,
1120011208
UNSAFE_allowJavascriptFileAttachments
1120111209
)}
11202-
${ESMVariables(moduleObject, importMap, {
11210+
${ESMVariables(moduleObject, importMap, {
1120311211
defineImportMarkdown,
1120411212
observeViewofValues,
1120511213
observeMutableValues
1120611214
}) || ""}
11207-
return main;
11208-
}`;
11215+
return main;
11216+
}`;
1120911217
}
1121011218

1121111219
function defaultResolveImportPath(path) {
@@ -11384,8 +11392,8 @@ var dist = {exports: {}};
1138411392
null,
1138511393
["md"],
1138611394
md => md`~~~javascript
11387-
${importString}
11388-
~~~`
11395+
${importString}
11396+
~~~`
1138911397
);
1139011398
if (hasInjections) {
1139111399
const child = other.derive(injections, module);
@@ -16963,7 +16971,7 @@ pp.readWord = function() {
1696316971

1696416972
// Acorn is a tiny, fast JavaScript parser written in JavaScript.
1696516973

16966-
var version = "8.8.0";
16974+
var version = "8.8.1";
1696716975

1696816976
Parser.acorn = {
1696916977
Parser: Parser,

src/resources/formats/html/ojs/quarto-ojs-runtime.min.js

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)