feat: locale support for date filter, #567 (#723)

This commit is contained in:
Jun Yang
2024-07-22 00:39:44 +08:00
committed by GitHub
parent 542a75fd44
commit e4aeb023fd
29 changed files with 511 additions and 318 deletions
+12
View File
@@ -33,6 +33,12 @@ describe('DoS related', function () {
await expect(limit10.parseAndRender(src)).rejects.toThrow('template render limit exceeded')
await expect(limit20.parseAndRender(src)).resolves.toBe('1,2,3,4,5,')
})
it('should support reset when calling render', async () => {
const src = '{% for i in (1..5) %}{{i}},{% endfor %}'
const liquid = new Liquid({ renderLimit: 0.01 })
await expect(liquid.parseAndRender(src)).rejects.toThrow('template render limit exceeded')
await expect(liquid.parseAndRender(src, {}, { renderLimit: 1e6 })).resolves.toBe('1,2,3,4,5,')
})
it('should take partials into account', async () => {
mock({
'/small': '{% for i in (1..5) %}{{i}}{% endfor %}',
@@ -50,6 +56,12 @@ describe('DoS related', function () {
await expect(liquid.parseAndRender('{{ array | slice: 0, 3 | join }}', { array })).resolves.toBe('0 0 0')
await expect(liquid.parseAndRender('{{ array | slice: 0, 300 | join }}', { array })).rejects.toThrow('memory alloc limit exceeded, line:1, col:1')
})
it('should support reset when calling render', async () => {
const array = Array(1e3).fill(0)
const liquid = new Liquid({ memoryLimit: 100 })
await expect(liquid.parseAndRender('{{ array | slice: 0, 300 | join }}', { array })).rejects.toThrow('memory alloc limit exceeded, line:1, col:1')
await expect(liquid.parseAndRender('{{ array | slice: 0, 300 | join }}', { array }, { memoryLimit: 1e3 })).resolves.toBe(Array(300).fill(0).join(' '))
})
it('should throw for too many array iteration in tags', async () => {
const array = ['a']
const liquid = new Liquid({ memoryLimit: 100 })
+3 -2
View File
@@ -9,7 +9,7 @@ describe('LiquidOptions#fs', function () {
existsSync: (x: string) => !x.match(/not-exist/),
readFile: (x: string) => Promise.resolve(`content for ${x}`),
readFileSync: (x: string) => `content for ${x}`,
fallback: (x: string) => '/root/files/fallback',
fallback: (_x: string) => '/root/files/fallback',
resolve: (base: string, path: string) => base + '/' + path
}
beforeEach(function () {
@@ -49,7 +49,7 @@ describe('LiquidOptions#fs', function () {
} as any)
expect(engine.options.relativeReference).toBe(false)
})
it('should render from in-memory templates', () => {
it('should render from in-memory templates', async () => {
const engine = new Liquid({
templates: {
entry: '{% layout "main" %}entry',
@@ -57,6 +57,7 @@ describe('LiquidOptions#fs', function () {
}
})
expect(engine.renderFileSync('entry')).toEqual('header entry footer')
await expect(engine.renderFile('entry')).resolves.toEqual('header entry footer')
})
it('should render relative in-memory templates', () => {
const engine = new Liquid({