From 4f9a49988a93c156524981e189a4fec238e682b8 Mon Sep 17 00:00:00 2001 From: Timmy Braun <35117769+timbze@users.noreply.github.com> Date: Tue, 7 Apr 2026 10:10:33 -0600 Subject: [PATCH] fix: null date should return empty (#868) (#872) --- src/filters/date.ts | 4 +++- test/integration/filters/date.spec.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/filters/date.ts b/src/filters/date.ts index 5f86178ce..6bbef46c3 100644 --- a/src/filters/date.ts +++ b/src/filters/date.ts @@ -45,7 +45,9 @@ function parseDate (v: string | Date, opts: NormalizedFullOptions, timezoneOffse const defaultTimezoneOffset = timezoneOffset ?? opts.timezoneOffset const locale = opts.locale v = toValue(v) - if (v === 'now' || v === 'today') { + if (isNil(v)) { + return undefined + } else if (v === 'now' || v === 'today') { date = new LiquidDate(Date.now(), locale, defaultTimezoneOffset) } else if (isNumber(v)) { date = new LiquidDate(v * 1000, locale, defaultTimezoneOffset) diff --git a/test/integration/filters/date.spec.ts b/test/integration/filters/date.spec.ts index 294d48dc0..384aecedf 100644 --- a/test/integration/filters/date.spec.ts +++ b/test/integration/filters/date.spec.ts @@ -21,8 +21,12 @@ describe('filters/date', function () { const time = String(new Date('2017-03-07T12:00:00').getTime() / 1000) return test('{{ time | date: "%Y-%m-%dT%H:%M:%S" }}', { time }, '2017-03-07T12:00:00') }) - it('should treat nil as 0', () => { - expect(liquid.parseAndRenderSync('{{ nil | date: "%Y-%m-%dT%H:%M:%S", "Asia/Shanghai" }}')).toEqual('1970-01-01T08:00:00') + it('should treat null as invalid', () => { + const time = null + return test('{{ time | date: "%Y-%m-%dT%H:%M:%S" }}', { time }, '') + }) + it('should treat nil as invalid', () => { + expect(liquid.parseAndRenderSync('{{ nil | date: "%Y-%m-%dT%H:%M:%S", "Asia/Shanghai" }}')).toEqual('') }) it('should treat undefined as invalid', () => { expect(liquid.parseAndRenderSync('{{ num | date: "%Y-%m-%dT%H:%M:%S", "Asia/Shanghai" }}', { num: undefined })).toEqual('')