From ec6ef6d8b37c1501924b50f6f26974e26e900e9f Mon Sep 17 00:00:00 2001 From: Alexey Date: Sun, 29 Mar 2020 23:12:55 +0300 Subject: [PATCH] Iterate only own properties --- nunjucks/src/lib.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/nunjucks/src/lib.js b/nunjucks/src/lib.js index 6fda6eae..dec92068 100644 --- a/nunjucks/src/lib.js +++ b/nunjucks/src/lib.js @@ -196,6 +196,13 @@ function getAttrGetter(attribute, postprocess, defaultValue) { return function attrGetter(item) { let _item = item; + function rollback() { + _item = undefined; + if (defaultValue) { + _item = defaultValue; + } + } + for (let i = 0; i < parts.length; i++) { const part = parts[i]; @@ -203,12 +210,15 @@ function getAttrGetter(attribute, postprocess, defaultValue) { // that something goes wrong. Just roll out to undefined or default value // in that case. try { - _item = _item[part]; - } catch (e) { - _item = undefined; - if (defaultValue) { - _item = defaultValue; + if (hasOwnProp(_item, part)) { + _item = _item[part]; + } else { + rollback(); + + break; } + } catch (e) { + rollback(); break; }