Skip to content

Commit c2f4b93

Browse files
authored
fix: STRF-9835 Reduce proto usage (#167)
1 parent 71a0cd9 commit c2f4b93

10 files changed

Lines changed: 74 additions & 7 deletions

File tree

helpers/decrementVar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const factory = globals => {
1313
globals.storage.variables = {};
1414
}
1515

16-
if (Number.isInteger(globals.storage.variables[key])) {
16+
if (globals.storage.variables.hasOwnProperty(key) &&Number.isInteger(globals.storage.variables[key])) {
1717
// Decrement value if it already exists
1818
globals.storage.variables[key] -= 1;
1919
} else {
@@ -26,7 +26,7 @@ const factory = globals => {
2626
}
2727

2828
// Return current value
29-
return globals.storage.variables[key];
29+
return globals.storage.variables.hasOwnProperty(key) ? globals.storage.variables[key]: undefined;
3030
};
3131
};
3232

helpers/dynamicComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const factory = globals => {
1919

2020
path = Path.join(path, this['partial']);
2121

22-
if (globals.handlebars.partials[path]) {
22+
if (globals.handlebars.partials[path] && globals.handlebars.partials.hasOwnProperty(path)) {
2323
return globals.handlebars.partials[path](this);
2424
}
2525
};

helpers/getVar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const factory = globals => {
77
throw new Error("getVar helper key must be a string");
88
}
99

10-
return globals.storage.variables ? globals.storage.variables[key] : undefined
10+
return globals.storage.variables && globals.storage.variables.hasOwnProperty(key) ? globals.storage.variables[key] : undefined
1111
};
1212
};
1313

helpers/incrementVar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const factory = globals => {
1313
globals.storage.variables = {};
1414
}
1515

16-
if (Number.isInteger(globals.storage.variables[key])) {
16+
if (globals.storage.variables.hasOwnProperty(key) && Number.isInteger(globals.storage.variables[key])) {
1717
// Increment value if it already exists
1818
globals.storage.variables[key] += 1;
1919
} else {
@@ -26,7 +26,7 @@ const factory = globals => {
2626
}
2727

2828
// Return current value
29-
return globals.storage.variables[key];
29+
return globals.storage.variables.hasOwnProperty(key) ? globals.storage.variables[key]: undefined;
3030
};
3131
};
3232

helpers/pluck.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var _ = require('lodash');
44

55
const factory = () => {
66
return function(collection, path) {
7-
return _.map(collection, item => item[path]);
7+
return _.map(collection, item => item.hasOwnProperty(path) ? item[path] : undefined);
88
};
99
};
1010

spec/helpers/assignVar-getVar.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,17 @@ describe('assignVar and getVar helpers', function() {
8383
done();
8484
});
8585
});
86+
87+
it('should return undefined accessing proto/constructor', function(done) {
88+
runTestCases([
89+
{
90+
input: "{{getVar '__proto__'}}",
91+
output: '',
92+
},
93+
{
94+
input: "{{getVar 'constructor'}}",
95+
output: '',
96+
},
97+
], done);
98+
});
8699
});

spec/helpers/decrementVar.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,17 @@ describe('decrementVar helper', function() {
5454
},
5555
], done);
5656
});
57+
58+
it('should correctly return data accession object proto/constructor', function(done) {
59+
runTestCases([
60+
{
61+
input: "{{decrementVar '__proto__'}}",
62+
output: '',
63+
},
64+
{
65+
input: "{{decrementVar 'constructor'}}",
66+
output: '0',
67+
},
68+
], done);
69+
});
5770
});

spec/helpers/dynamicComponent.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,18 @@ describe('dynamicComponent helper', function() {
3030
},
3131
], done);
3232
});
33+
34+
it('should return undefined when accessing proto/constructor', function(done) {
35+
runTestCases([
36+
{
37+
input: '{{#each fields}}{{dynamicComponent "__proto__"}}{{/each}}',
38+
output: '',
39+
},
40+
{
41+
input: '{{#each fields}}{{dynamicComponent "constructor"}}{{/each}}',
42+
output: '',
43+
},
44+
], done);
45+
});
3346
});
3447

spec/helpers/incrementVar.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,19 @@ describe('incrementVar helper', function() {
5454
},
5555
], done);
5656
});
57+
58+
59+
60+
it('should correctly return data accession object proto/constructor', function(done) {
61+
runTestCases([
62+
{
63+
input: "{{incrementVar '__proto__'}}",
64+
output: '',
65+
},
66+
{
67+
input: "{{incrementVar 'constructor'}}",
68+
output: '0',
69+
},
70+
], done);
71+
});
5772
});

spec/helpers/pluck.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,17 @@ describe('pluck helper', function() {
2626
},
2727
], done);
2828
});
29+
30+
it('should return undefined when accessing proto/constructor', function(done) {
31+
runTestCases([
32+
{
33+
input: '{{pluck users "__proto__"}}',
34+
output: ',',
35+
},
36+
{
37+
input: '{{pluck users "constructor"}}',
38+
output: ',',
39+
},
40+
], done);
41+
});
2942
});

0 commit comments

Comments
 (0)