Skip to content

Build your personal knowledge base with Trilium Notes

fix(template_field): offer nothing after an inherited name

Elian Doran32e9a731636e
diff --git a/apps/client/src/widgets/bulk_actions/template_completions.spec.ts b/apps/client/src/widgets/bulk_actions/template_completions.spec.ts
index 895777543e..a6a9245f7b 100644
--- a/apps/client/src/widgets/bulk_actions/template_completions.spec.ts
+++ b/apps/client/src/widgets/bulk_actions/template_completions.spec.ts
@@ -39,6 +39,12 @@ describe("templateCompletionAt", () => {
expect(titlesAt("${other.")).toBeNull();
});
+ it("offers nothing after a name inherited from Object.prototype", () => {
+ expect(titlesAt("${constructor.")).toBeNull();
+ expect(titlesAt("${constructor.title.")).toBeNull();
+ expect(titlesAt("${__proto__.")).toBeNull();
+ });
+
it("offers only what the template engine allows", () => {
for (const member of NOTE_TEMPLATE_MEMBERS) {
const allowed = member.kind === "method" ? TEMPLATE_ALLOWED_METHODS : TEMPLATE_ALLOWED_PROPERTIES;
diff --git a/apps/client/src/widgets/bulk_actions/template_completions.ts b/apps/client/src/widgets/bulk_actions/template_completions.ts
index a337f92455..e0b0285688 100644
--- a/apps/client/src/widgets/bulk_actions/template_completions.ts
+++ b/apps/client/src/widgets/bulk_actions/template_completions.ts
@@ -113,7 +113,7 @@ export function templateCompletionAt(before: string, variables: TemplateVariable
}
function resolvePathType([ root, ...properties ]: string[], variables: TemplateVariableTypes): TemplateValueType | undefined {
- let type: TemplateValueType | undefined = variables[root];
+ let type: TemplateValueType | undefined = Object.hasOwn(variables, root) ? variables[root] : undefined;
for (const property of properties) {
type = type && MEMBERS[type].find((m) => m.kind === "property" && m.name === property)?.type;
}