mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 05:50:43 -07:00
@@ -33,6 +33,12 @@ describe('DoS related', function () {
|
||||
await expect(limit10.parseAndRender(src)).rejects.toThrow('template render limit exceeded')
|
||||
await expect(limit20.parseAndRender(src)).resolves.toBe('1,2,3,4,5,')
|
||||
})
|
||||
it('should support reset when calling render', async () => {
|
||||
const src = '{% for i in (1..5) %}{{i}},{% endfor %}'
|
||||
const liquid = new Liquid({ renderLimit: 0.01 })
|
||||
await expect(liquid.parseAndRender(src)).rejects.toThrow('template render limit exceeded')
|
||||
await expect(liquid.parseAndRender(src, {}, { renderLimit: 1e6 })).resolves.toBe('1,2,3,4,5,')
|
||||
})
|
||||
it('should take partials into account', async () => {
|
||||
mock({
|
||||
'/small': '{% for i in (1..5) %}{{i}}{% endfor %}',
|
||||
@@ -50,6 +56,12 @@ describe('DoS related', function () {
|
||||
await expect(liquid.parseAndRender('{{ array | slice: 0, 3 | join }}', { array })).resolves.toBe('0 0 0')
|
||||
await expect(liquid.parseAndRender('{{ array | slice: 0, 300 | join }}', { array })).rejects.toThrow('memory alloc limit exceeded, line:1, col:1')
|
||||
})
|
||||
it('should support reset when calling render', async () => {
|
||||
const array = Array(1e3).fill(0)
|
||||
const liquid = new Liquid({ memoryLimit: 100 })
|
||||
await expect(liquid.parseAndRender('{{ array | slice: 0, 300 | join }}', { array })).rejects.toThrow('memory alloc limit exceeded, line:1, col:1')
|
||||
await expect(liquid.parseAndRender('{{ array | slice: 0, 300 | join }}', { array }, { memoryLimit: 1e3 })).resolves.toBe(Array(300).fill(0).join(' '))
|
||||
})
|
||||
it('should throw for too many array iteration in tags', async () => {
|
||||
const array = ['a']
|
||||
const liquid = new Liquid({ memoryLimit: 100 })
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('LiquidOptions#fs', function () {
|
||||
existsSync: (x: string) => !x.match(/not-exist/),
|
||||
readFile: (x: string) => Promise.resolve(`content for ${x}`),
|
||||
readFileSync: (x: string) => `content for ${x}`,
|
||||
fallback: (x: string) => '/root/files/fallback',
|
||||
fallback: (_x: string) => '/root/files/fallback',
|
||||
resolve: (base: string, path: string) => base + '/' + path
|
||||
}
|
||||
beforeEach(function () {
|
||||
@@ -49,7 +49,7 @@ describe('LiquidOptions#fs', function () {
|
||||
} as any)
|
||||
expect(engine.options.relativeReference).toBe(false)
|
||||
})
|
||||
it('should render from in-memory templates', () => {
|
||||
it('should render from in-memory templates', async () => {
|
||||
const engine = new Liquid({
|
||||
templates: {
|
||||
entry: '{% layout "main" %}entry',
|
||||
@@ -57,6 +57,7 @@ describe('LiquidOptions#fs', function () {
|
||||
}
|
||||
})
|
||||
expect(engine.renderFileSync('entry')).toEqual('header entry footer')
|
||||
await expect(engine.renderFile('entry')).resolves.toEqual('header entry footer')
|
||||
})
|
||||
it('should render relative in-memory templates', () => {
|
||||
const engine = new Liquid({
|
||||
|
||||
Reference in New Issue
Block a user