0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Fixed clobbering the lodash template settings

refs: https://github.com/lodash/lodash/issues/705

- Was seeing unexpected token = errors when using lodash templates in Ghost
- This is because we're setting template settings globally in this dependency and it affects every other user of lodash
- Using runInContext keeps this templateSettings change local to this lib
- Test proves that after requiring limits we can require lodash and have the default values again
This commit is contained in:
Hannah Wolfe 2021-03-03 17:50:17 +00:00
parent 7dc95f96c4
commit feb872eb3e
3 changed files with 14 additions and 11 deletions

View file

@ -1,6 +1,7 @@
const errors = require('@tryghost/errors');
const _ = require('lodash');
// run in context allows us to change the templateSettings without causing havoc
const _ = require('lodash').runInContext();
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
class Limit {

View file

@ -1,10 +0,0 @@
// Switch these lines once there are useful utils
// const testUtils = require('./utils');
require('./utils');
describe('Hello world', function () {
it('Runs a test', function () {
// TODO: Write me!
'hello'.should.eql('hello');
});
});

View file

@ -0,0 +1,12 @@
// Switch these lines once there are useful utils
// const testUtils = require('./utils');
require('./utils');
describe('Lodash Template', function () {
it('Does not get clobbered by this lib', function () {
require('../lib/limit');
let _ = require('lodash');
_.templateSettings.interpolate.should.eql(/<%=([\s\S]+?)%>/g);
});
});