Skip to content

Commit

Permalink
fix: memory limit issue for join filter, fix #737
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Aug 23, 2024
1 parent 292a93b commit 2d59cff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/filters/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Scope } from '../context'

export const join = argumentsToValue(function (this: FilterImpl, v: any[], arg: string) {
const array = toArray(v)
const sep = arg === undefined ? ' ' : arg
const sep = isNil(arg) ? ' ' : stringify(arg)
const complexity = array.length * (1 + sep.length)
this.context.memoryLimit.use(complexity)
return array.join(sep)
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/issues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,10 @@ describe('Issues', function () {
const liquid = new Liquid()
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')
})
})

0 comments on commit 2d59cff

Please sign in to comment.