mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
fix: inconsistent continue behaviour, fixes #779
This commit is contained in:
@@ -525,8 +525,10 @@ describe('Issues', function () {
|
||||
expect(result).toEqual('\n[2,12] foo')
|
||||
})
|
||||
it("memoryLimit doesn't work in for tag #776", () => {
|
||||
const engine = new Liquid()
|
||||
const engine = new Liquid({
|
||||
memoryLimit: 1e5
|
||||
})
|
||||
const tpl = `{% for i in (1..1000000000) %} {{'a'}} {% endfor %}`
|
||||
expect(() => engine.parseAndRenderSync(tpl)).toThrow(/memory out/)
|
||||
expect(() => engine.parseAndRenderSync(tpl)).toThrow('memory alloc limit exceeded, line:1, col:1')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { Drop } from '../../../src/drop/drop'
|
||||
import { Scope } from '../../../src/context/scope'
|
||||
import { mock, restore } from '../../stub/mockfs'
|
||||
|
||||
describe('tags/for', function () {
|
||||
let liquid: Liquid, scope: Scope
|
||||
@@ -139,6 +140,7 @@ describe('tags/for', function () {
|
||||
})
|
||||
|
||||
describe('continue', function () {
|
||||
afterEach(restore)
|
||||
it('should support for with continue', async function () {
|
||||
const src = '{% for i in (1..5) %}' +
|
||||
'{% if i == 4 %}continue{% continue %}{% endif %}{{i}}' +
|
||||
@@ -154,6 +156,28 @@ describe('tags/for', function () {
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).toBe('123continue5')
|
||||
})
|
||||
it('should skip snippet for rendered continue', async function () {
|
||||
mock({
|
||||
'snippet.liquid': ' before{% continue %}skipped'
|
||||
})
|
||||
const src = '{% for i in (1..2) %}' +
|
||||
'{% render "snippet.liquid" %}' +
|
||||
' after' +
|
||||
'{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).toBe(' before after before after')
|
||||
})
|
||||
it('should skip `for` body for included continue', async function () {
|
||||
mock({
|
||||
'snippet.liquid': ' before{% continue %}skipped'
|
||||
})
|
||||
const src = '{% for i in (1..2) %}' +
|
||||
'{% include "snippet.liquid" %}' +
|
||||
' after' +
|
||||
'{% endfor %}'
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).toBe(' before before')
|
||||
})
|
||||
})
|
||||
describe('break', function () {
|
||||
it('should support break', async function () {
|
||||
|
||||
Reference in New Issue
Block a user