mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: memory limit issue for join filter, fix #737
This commit is contained in:
@@ -6,7 +6,7 @@ import type { Scope } from '../context'
|
|||||||
|
|
||||||
export const join = argumentsToValue(function (this: FilterImpl, v: any[], arg: string) {
|
export const join = argumentsToValue(function (this: FilterImpl, v: any[], arg: string) {
|
||||||
const array = toArray(v)
|
const array = toArray(v)
|
||||||
const sep = arg === undefined ? ' ' : arg
|
const sep = isNil(arg) ? ' ' : stringify(arg)
|
||||||
const complexity = array.length * (1 + sep.length)
|
const complexity = array.length * (1 + sep.length)
|
||||||
this.context.memoryLimit.use(complexity)
|
this.context.memoryLimit.use(complexity)
|
||||||
return array.join(sep)
|
return array.join(sep)
|
||||||
|
|||||||
@@ -495,4 +495,10 @@ describe('Issues', function () {
|
|||||||
const liquid = new Liquid()
|
const liquid = new Liquid()
|
||||||
expect(() => liquid.parse({} as any)).not.toThrow()
|
expect(() => liquid.parse({} as any)).not.toThrow()
|
||||||
})
|
})
|
||||||
|
it('Unexpected "RenderError: memory alloc limit exceeded" #737', () => {
|
||||||
|
const liquid = new Liquid();
|
||||||
|
const context = { x: ["a", "b"] };
|
||||||
|
const template = "{{ x | join: 5 }}"
|
||||||
|
expect(liquid.parseAndRender(template, context)).resolves.toEqual('a5b')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user