mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
fix: operator boundary not correctly recognized, fixes #342
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { IDENTIFIER } from '../util/character'
|
import { IDENTIFIER, TYPES } from '../util/character'
|
||||||
import { Trie } from '../util/operator-trie'
|
import { Trie } from '../util/operator-trie'
|
||||||
|
|
||||||
export function matchOperator (str: string, begin: number, trie: Trie, end = str.length) {
|
export function matchOperator (str: string, begin: number, trie: Trie, end = str.length) {
|
||||||
@@ -10,6 +10,6 @@ export function matchOperator (str: string, begin: number, trie: Trie, end = str
|
|||||||
if (node['end']) info = node
|
if (node['end']) info = node
|
||||||
}
|
}
|
||||||
if (!info) return -1
|
if (!info) return -1
|
||||||
if (info['needBoundary'] && str.charCodeAt(i) & IDENTIFIER) return -1
|
if (info['needBoundary'] && (TYPES[str.charCodeAt(i)] & IDENTIFIER)) return -1
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Operators } from '../render/operator'
|
import { Operators } from '../render/operator'
|
||||||
|
import { IDENTIFIER, TYPES } from '../util/character'
|
||||||
|
|
||||||
export interface Trie {
|
export interface Trie {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
@@ -13,7 +14,7 @@ export function createTrie (operators: Operators): Trie {
|
|||||||
const c = name[i]
|
const c = name[i]
|
||||||
node[c] = node[c] || {}
|
node[c] = node[c] || {}
|
||||||
|
|
||||||
if (i === name.length - 1 && c !== '=') {
|
if (i === name.length - 1 && (TYPES[name.charCodeAt(i)] & IDENTIFIER)) {
|
||||||
node[c].needBoundary = true
|
node[c].needBoundary = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -95,11 +95,17 @@ describe('Issues', function () {
|
|||||||
)
|
)
|
||||||
expect(html).to.equal('falsefalse')
|
expect(html).to.equal('falsefalse')
|
||||||
})
|
})
|
||||||
it('#321 comparison for empty/nil', async () => {
|
it('#320 newline_to_br filter should output <br /> instead of <br/>', async () => {
|
||||||
const engine = new Liquid()
|
const engine = new Liquid()
|
||||||
const html = await engine.parseAndRender(
|
const html = await engine.parseAndRender(
|
||||||
`{{ 'a \n b \n c' | newline_to_br | split: '<br />' }}`
|
`{{ 'a \n b \n c' | newline_to_br | split: '<br />' }}`
|
||||||
)
|
)
|
||||||
expect(html).to.equal('a ,\n b ,\n c')
|
expect(html).to.equal('a ,\n b ,\n c')
|
||||||
})
|
})
|
||||||
|
it('#342 New lines in logical operator', async () => {
|
||||||
|
const engine = new Liquid()
|
||||||
|
const tpl = `{%\r\nif\r\ntrue\r\nor\r\nfalse\r\n%}\r\ntrue\r\n{%\r\nendif\r\n%}`
|
||||||
|
const html = await engine.parseAndRender(tpl)
|
||||||
|
expect(html).to.equal('\r\ntrue\r\n')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user