Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit d6482db

Browse files
committed
fix(plugins/plugin-client-common): avoid infinite loop in snippet inliner
e.g. if you have a *file* named "foo.md" that inlines a snippet named "foo.md", the interpretation is that the latter comes from the "snippets" basepath, but kui gets into an infinite loop
1 parent d4765c5 commit d6482db

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

plugins/plugin-client-common/src/controller/snippets.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ export default function inlineSnippets(snippetBasePath?: string) {
103103

104104
const candidates = match[5]
105105
? [match[5]]
106-
: snippetBasePath
107-
? [snippetBasePath]
108-
: ['./', '../', '../snippets', '../../snippets']
106+
: ['./', snippetBasePath, '../', '../snippets', '../../snippets'].filter(Boolean)
109107

110108
const snippetData = isUrl(snippetFileName)
111109
? await loadNotebook(snippetFileName, args)
@@ -118,12 +116,16 @@ export default function inlineSnippets(snippetBasePath?: string) {
118116
await Promise.all(
119117
candidates
120118
.map(getBasePath)
121-
.filter(Boolean)
122-
.map(mySnippetBasePath =>
123-
loadNotebook(join(mySnippetBasePath, snippetFileName), args)
124-
.then(data => recurse(mySnippetBasePath, toString(data)))
119+
.map(myBasePath => ({
120+
myBasePath,
121+
filepath: join(myBasePath, snippetFileName)
122+
}))
123+
.filter(_ => _ && _.filepath !== srcFilePath) // avoid cycles
124+
.map(({ myBasePath, filepath }) =>
125+
loadNotebook(filepath, args)
126+
.then(data => recurse(myBasePath, toString(data)))
125127
.catch(err => {
126-
debug('Warning: could not fetch inlined content 2', mySnippetBasePath, mySnippetBasePath, err)
128+
debug('Warning: could not fetch inlined content 2', myBasePath, err)
127129
return ''
128130
})
129131
)

0 commit comments

Comments
 (0)