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 1d9408b
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();

Check failure on line 499 in test/e2e/issues.spec.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Extra semicolon
const context = { x: ["a", "b"] };

Check failure on line 500 in test/e2e/issues.spec.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Strings must use singlequote

Check failure on line 500 in test/e2e/issues.spec.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Strings must use singlequote

Check failure on line 500 in test/e2e/issues.spec.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Extra semicolon
const template = "{{ x | join: 5 }}"

Check failure on line 501 in test/e2e/issues.spec.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Strings must use singlequote
expect(liquid.parseAndRender(template, context)).resolves.toEqual('a5b')
})
})

0 comments on commit 1d9408b

Please sign in to comment.