From 2d59cff0a6162b462b4d97ebea4e0dbaf6146b65 Mon Sep 17 00:00:00 2001 From: Yang Jun Date: Fri, 23 Aug 2024 20:56:41 +0800 Subject: [PATCH] fix: memory limit issue for join filter, fix #737 --- src/filters/array.ts | 2 +- test/e2e/issues.spec.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/filters/array.ts b/src/filters/array.ts index 8d716a88b0..211c8e026b 100644 --- a/src/filters/array.ts +++ b/src/filters/array.ts @@ -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) diff --git a/test/e2e/issues.spec.ts b/test/e2e/issues.spec.ts index 5812e1a195..d55f6da160 100644 --- a/test/e2e/issues.spec.ts +++ b/test/e2e/issues.spec.ts @@ -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') + }) })