Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: STRF-9835 Reduce proto usage #167

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions helpers/decrementVar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const factory = globals => {
globals.storage.variables = {};
}

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

// Return current value
return globals.storage.variables[key];
return globals.storage.variables.hasOwnProperty(key) ? globals.storage.variables[key]: undefined;
};
};

Expand Down
2 changes: 1 addition & 1 deletion helpers/dynamicComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const factory = globals => {

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

if (globals.handlebars.partials[path]) {
if (globals.handlebars.partials[path] && globals.handlebars.partials.hasOwnProperty(path)) {
return globals.handlebars.partials[path](this);
}
};
Expand Down
2 changes: 1 addition & 1 deletion helpers/getVar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const factory = globals => {
throw new Error("getVar helper key must be a string");
}

return globals.storage.variables ? globals.storage.variables[key] : undefined
return globals.storage.variables && globals.storage.variables.hasOwnProperty(key) ? globals.storage.variables[key] : undefined
};
};

Expand Down
4 changes: 2 additions & 2 deletions helpers/incrementVar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const factory = globals => {
globals.storage.variables = {};
}

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

// Return current value
return globals.storage.variables[key];
return globals.storage.variables.hasOwnProperty(key) ? globals.storage.variables[key]: undefined;
};
};

Expand Down
2 changes: 1 addition & 1 deletion helpers/pluck.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var _ = require('lodash');

const factory = () => {
return function(collection, path) {
return _.map(collection, item => item[path]);
return _.map(collection, item => item.hasOwnProperty(path) ? item[path] : undefined);
};
};

Expand Down
13 changes: 13 additions & 0 deletions spec/helpers/assignVar-getVar.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,17 @@ describe('assignVar and getVar helpers', function() {
done();
});
});

it('should return undefined accessing proto/constructor', function(done) {
runTestCases([
{
input: "{{getVar '__proto__'}}",
output: '',
},
{
input: "{{getVar 'constructor'}}",
output: '',
},
], done);
});
});
13 changes: 13 additions & 0 deletions spec/helpers/decrementVar.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,17 @@ describe('decrementVar helper', function() {
},
], done);
});

it('should correctly return data accession object proto/constructor', function(done) {
runTestCases([
{
input: "{{decrementVar '__proto__'}}",
output: '',
},
{
input: "{{decrementVar 'constructor'}}",
output: '0',
},
], done);
});
});
13 changes: 13 additions & 0 deletions spec/helpers/dynamicComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,18 @@ describe('dynamicComponent helper', function() {
},
], done);
});

it('should return undefined when accessing proto/constructor', function(done) {
runTestCases([
{
input: '{{#each fields}}{{dynamicComponent "__proto__"}}{{/each}}',
output: '',
},
{
input: '{{#each fields}}{{dynamicComponent "constructor"}}{{/each}}',
output: '',
},
], done);
});
});

15 changes: 15 additions & 0 deletions spec/helpers/incrementVar.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,19 @@ describe('incrementVar helper', function() {
},
], done);
});



it('should correctly return data accession object proto/constructor', function(done) {
runTestCases([
{
input: "{{incrementVar '__proto__'}}",
output: '',
},
{
input: "{{incrementVar 'constructor'}}",
output: '0',
},
], done);
});
});
13 changes: 13 additions & 0 deletions spec/helpers/pluck.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@ describe('pluck helper', function() {
},
], done);
});

it('should return undefined when accessing proto/constructor', function(done) {
runTestCases([
{
input: '{{pluck users "__proto__"}}',
output: ',',
},
{
input: '{{pluck users "constructor"}}',
output: ',',
},
], done);
});
});