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-12532 Set Access has been denied to resolve the property message to info level #333

Merged
merged 1 commit into from
Oct 8, 2024
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
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ class HandlebarsRenderer {
let method = this.handlebars.logger.methodMap[level];
if (typeof this.logger[method] !== 'function') {
method = 'log';
} else if (this._overrideHandlebarsAccessDeniedToPropertyMessageLevel(...message)) {
method = 'info';
}
this.logger[method](...message);
}
Expand All @@ -395,14 +397,20 @@ class HandlebarsRenderer {
* As some handlebars helpers do not use the logger, we need to override the console.log method
*/
_overrideConsoleLog() {
this.isLoggerOverriden = false;
if (this.logger !== console) {
console.log = this.logger.info.bind(this.logger);
console.info = this.logger.info.bind(this.logger);
console.error = this.logger.error.bind(this.logger);
console.warn = this.logger.warn.bind(this.logger);
this.isLoggerOverriden = true;
}
}

_overrideHandlebarsAccessDeniedToPropertyMessageLevel(message) {
return this.isLoggerOverriden && message.includes('Handlebars: Access has been denied to resolve the property');
}

/**
*
* @param {String} level
Expand Down
16 changes: 16 additions & 0 deletions spec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,22 @@ describe('logging', () => {
done();
});

it('should check that property access denied message is set as info', async () => {
const renderer = new HandlebarsRenderer({}, {}, 'v4', logger);
const result = await renderer.renderString("{{aString.trim}}", { aString: " abc " });
expect(result).to.equal("");
expect(logger.info.calledWith('Handlebars: Access has been denied to resolve the property "trim" because it is not an "own property" of its parent.\n' + 'You can add a runtime option to disable the check or this warning:\n' + 'See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details'))
.to.equal(true);
});

it('should check that property access denied message is set as error', async () => {
console.error = Sinon.fake();
const renderer = new HandlebarsRenderer({}, {}, 'v4', console);
const result = await renderer.renderString("{{aString.toLowerCase}}", { aString: " abc " });
expect(result).to.equal("");
expect(console.error.calledWith('Handlebars: Access has been denied to resolve the property "toLowerCase" because it is not an "own property" of its parent.\n' + 'You can add a runtime option to disable the check or this warning:\n' + 'See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details'))
.to.equal(true);
});
});

// STRF-12276
Expand Down
Loading