Skip to content

Commit 2d0188b

Browse files
authored
Merge pull request #9428 from quarto-dev/bugfix/9426
update crossref.lua to use quarto_ast_pipeline
2 parents cbc7b70 + df9f510 commit 2d0188b

File tree

4 files changed

+19
-29
lines changed

4 files changed

+19
-29
lines changed

news/changelog-1.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ All changes included in 1.5:
155155
- ([#9059](https://github.com/quarto-dev/quarto-cli/issues/9059)): `quarto run` now properly works on Windows with Lua scripts.
156156
- ([#9282](https://github.com/quarto-dev/quarto-cli/issues/9282)): Fix name clash in Lua local declarations for `mediabag` in bundled releases.
157157
- ([#9394](https://github.com/quarto-dev/quarto-cli/issues/9394)): Make `template` a required field in the `about` schema.
158+
- ([#9426](https://github.com/quarto-dev/quarto-cli/issues/9426)): Update `crossref.lua` filter to avoid crashes and hangs in documents with custom AST nodes.
158159
- Add support for `{{< lipsum >}}` shortcode, which is useful for emitting placeholder text. Provide a specific number of paragraphs (`{{< lipsum 3 >}}`).
159160
- Resolve data URIs in Pandoc's mediabag when rendering documents.
160161
- Increase v8's max heap size by default, to avoid out-of-memory errors when rendering large documents (also cf. https://github.com/denoland/deno/issues/18935).

src/command/editor-support/crossref.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ const makeCrossrefCommand = () => {
126126
stdout: "piped",
127127
},
128128
input,
129+
undefined, // mergeOutput?: "stderr>stdout" | "stdout>stderr",
130+
undefined, // stderrFilter?: (output: string) => string,
131+
undefined, // respectStreams?: boolean,
132+
5000,
129133
);
130134

131135
// check for error

src/core/process.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ export async function execProcess(
3636
mergeOutput?: "stderr>stdout" | "stdout>stderr",
3737
stderrFilter?: (output: string) => string,
3838
respectStreams?: boolean,
39+
timeout?: number,
3940
): Promise<ProcessResult> {
41+
const withTimeout = <T>(promise: Promise<T>): Promise<T> => {
42+
return timeout
43+
? Promise.race([
44+
promise,
45+
new Promise((_, reject) =>
46+
setTimeout(() => reject(new Error("Process timed out")), timeout)
47+
),
48+
]) as Promise<T>
49+
: promise;
50+
};
4051
ensureCleanup();
4152
// define process
4253
try {
@@ -150,11 +161,11 @@ export async function execProcess(
150161
}),
151162
);
152163
}
153-
await Promise.all(promises);
164+
await withTimeout(Promise.all(promises));
154165
}
155166

156167
// await result
157-
const status = await process.status();
168+
const status = await withTimeout(process.status());
158169

159170
// close the process
160171
process.close();

src/resources/filters/crossref/crossref.lua

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -156,34 +156,8 @@ local quarto_normalize_filters = {
156156
end, normalize_filter()) },
157157

158158
{ name = "normalize-capture-reader-state", filter = normalize_capture_reader_state() },
159-
160-
{ name = "pre-table-merge-raw-html",
161-
filter = table_merge_raw_html()
162-
},
163-
164-
-- { name = "pre-content-hidden-meta",
165-
-- filter = content_hidden_meta() },
166-
167-
-- 2023-04-11: We want to combine combine-1 and combine-2, but parse_md_in_html_rawblocks
168-
-- can't be combined with parse_html_tables. combineFilters
169-
-- doesn't inspect the contents of the results in the inner loop in case
170-
-- the result is "spread" into a Blocks or Inlines.
171-
172-
{ name = "normalize-combined-1", filter = combineFilters({
173-
parse_html_tables(),
174-
parse_extended_nodes(),
175-
code_filename(),
176-
})
177-
},
178-
{
179-
name = "normalize-combine-2",
180-
filter = combineFilters({
181-
parse_md_in_html_rawblocks(),
182-
parse_floatreftargets(),
183-
parse_blockreftargets(),
184-
}),
185-
},
186159
}
160+
tappend(quarto_normalize_filters, quarto_ast_pipeline())
187161

188162
local quarto_pre_filters = {
189163
-- quarto-pre

0 commit comments

Comments
 (0)