From 40cb74ee28599bbde59bcab5b3fe1faca0ead2eb Mon Sep 17 00:00:00 2001 From: Dragory Date: Sat, 13 Apr 2019 04:11:24 +0300 Subject: [PATCH] evaluateTemplateVariable: require property to be a direct/own property of 'values', not from its prototype --- package-lock.json | 5 +++++ package.json | 1 + src/templateFormatter.ts | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 72615c7d..04f1caca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5528,6 +5528,11 @@ "resolved": "https://registry.npmjs.org/lodash.difference/-/lodash.difference-4.5.0.tgz", "integrity": "sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=" }, + "lodash.has": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz", + "integrity": "sha1-0Z9NwQlQWMzL4rDN9O4P5Ko3yGI=" + }, "lodash.intersection": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.intersection/-/lodash.intersection-4.4.0.tgz", diff --git a/package.json b/package.json index b87c6618..9ada51fe 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "lodash.at": "^4.6.0", "lodash.chunk": "^4.2.0", "lodash.difference": "^4.5.0", + "lodash.has": "^4.5.2", "lodash.intersection": "^4.4.0", "lodash.isequal": "^4.5.0", "moment-timezone": "^0.5.21", diff --git a/src/templateFormatter.ts b/src/templateFormatter.ts index 3b5ca217..d0637daa 100644 --- a/src/templateFormatter.ts +++ b/src/templateFormatter.ts @@ -1,3 +1,4 @@ +import has from "lodash.has"; import at from "lodash.at"; const TEMPLATE_CACHE_SIZE = 100; @@ -218,7 +219,7 @@ export function parseTemplate(str: string): ParsedTemplate { } async function evaluateTemplateVariable(theVar: ITemplateVar, values) { - const value = at(values, theVar.identifier)[0]; + const value = has(values, theVar.identifier) && at(values, theVar.identifier)[0]; if (typeof value === "function") { const args = [];