mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 20:30:39 -07:00
fix: allow quotes in inline comment tag, fixes #628
This commit is contained in:
@@ -67,6 +67,7 @@
|
|||||||
<td align="center" valign="top" width="0%"><a href="https://github.com/bangank36"><img src="https://avatars.githubusercontent.com/u/10071857?v=4?s=100" width="100px;" alt="BaNgan"/></a></td>
|
<td align="center" valign="top" width="0%"><a href="https://github.com/bangank36"><img src="https://avatars.githubusercontent.com/u/10071857?v=4?s=100" width="100px;" alt="BaNgan"/></a></td>
|
||||||
<td align="center" valign="top" width="0%"><a href="https://github.com/mahyar-pasarzangene"><img src="https://avatars.githubusercontent.com/u/16485039?v=4?s=100" width="100px;" alt="Mahyar Pasarzangene"/></a></td>
|
<td align="center" valign="top" width="0%"><a href="https://github.com/mahyar-pasarzangene"><img src="https://avatars.githubusercontent.com/u/16485039?v=4?s=100" width="100px;" alt="Mahyar Pasarzangene"/></a></td>
|
||||||
<td align="center" valign="top" width="0%"><a href="https://hubelbauer.net/"><img src="https://avatars.githubusercontent.com/u/6831144?v=4?s=100" width="100px;" alt="Tomáš Hübelbauer"/></a></td>
|
<td align="center" valign="top" width="0%"><a href="https://hubelbauer.net/"><img src="https://avatars.githubusercontent.com/u/6831144?v=4?s=100" width="100px;" alt="Tomáš Hübelbauer"/></a></td>
|
||||||
|
<td align="center" valign="top" width="0%"><a href="https://sixtwothree.org"><img src="https://avatars.githubusercontent.com/u/73866?v=4?s=100" width="100px;" alt="Jason Garber"/></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -199,15 +199,6 @@ describe('Tokenizer', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('#readTagToken()', () => {
|
describe('#readTagToken()', () => {
|
||||||
it('should skip quoted delimiters', function () {
|
|
||||||
const html = '{% assign a = "%} {% }} {{" %}'
|
|
||||||
const tokenizer = new Tokenizer(html)
|
|
||||||
const token = tokenizer.readTagToken()
|
|
||||||
|
|
||||||
expect(token).toBeInstanceOf(TagToken)
|
|
||||||
expect(token.name).toBe('assign')
|
|
||||||
expect(token.args).toBe('a = "%} {% }} {{"')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
describe('#readOutputToken()', () => {
|
describe('#readOutputToken()', () => {
|
||||||
it('should skip quoted delimiters', function () {
|
it('should skip quoted delimiters', function () {
|
||||||
|
|||||||
@@ -140,9 +140,10 @@ export class Tokenizer {
|
|||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
readToDelimiter (delimiter: string) {
|
readToDelimiter (delimiter: string, respectQuoted = false) {
|
||||||
|
this.skipBlank()
|
||||||
while (this.p < this.N) {
|
while (this.p < this.N) {
|
||||||
if ((this.peekType() & QUOTE)) {
|
if (respectQuoted && (this.peekType() & QUOTE)) {
|
||||||
this.readQuoted()
|
this.readQuoted()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -156,7 +157,7 @@ export class Tokenizer {
|
|||||||
const { file, input } = this
|
const { file, input } = this
|
||||||
const { outputDelimiterRight } = options
|
const { outputDelimiterRight } = options
|
||||||
const begin = this.p
|
const begin = this.p
|
||||||
if (this.readToDelimiter(outputDelimiterRight) === -1) {
|
if (this.readToDelimiter(outputDelimiterRight, true) === -1) {
|
||||||
throw this.error(`output ${this.snapshot(begin)} not closed`, begin)
|
throw this.error(`output ${this.snapshot(begin)} not closed`, begin)
|
||||||
}
|
}
|
||||||
return new OutputToken(input, begin, this.p, options, file)
|
return new OutputToken(input, begin, this.p, options, file)
|
||||||
|
|||||||
@@ -431,4 +431,27 @@ describe('Issues', function () {
|
|||||||
const fn = () => engine.parseAndRenderSync("{%- assign module = '' | split '' -%}")
|
const fn = () => engine.parseAndRenderSync("{%- assign module = '' | split '' -%}")
|
||||||
expect(fn).toThrow(/expected ":" after filter name/)
|
expect(fn).toThrow(/expected ":" after filter name/)
|
||||||
})
|
})
|
||||||
|
it('#628 Single or double quote breaks comments', () => {
|
||||||
|
const template = `{%- liquid
|
||||||
|
# Show a message that's customized to the product type
|
||||||
|
|
||||||
|
assign product_type = product.type | downcase
|
||||||
|
assign message = ''
|
||||||
|
|
||||||
|
case product_type
|
||||||
|
when 'health'
|
||||||
|
assign message = 'This is a health potion!'
|
||||||
|
when 'love'
|
||||||
|
assign message = 'This is a love potion!'
|
||||||
|
else
|
||||||
|
assign message = 'This is a potion!'
|
||||||
|
endcase
|
||||||
|
|
||||||
|
echo message
|
||||||
|
-%}`
|
||||||
|
const engine = new Liquid()
|
||||||
|
const product = { type: 'love' }
|
||||||
|
const result = engine.parseAndRenderSync(template, { product })
|
||||||
|
expect(result).toEqual('This is a love potion!')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -17,6 +17,16 @@ describe('tags/inline-comment', function () {
|
|||||||
const html = await liquid.parseAndRender(src)
|
const html = await liquid.parseAndRender(src)
|
||||||
return expect(html).toBe('foo')
|
return expect(html).toBe('foo')
|
||||||
})
|
})
|
||||||
|
it('should allow single quotes', async function () {
|
||||||
|
const src = "B{% # that's %}A"
|
||||||
|
const html = await liquid.parseAndRender(src)
|
||||||
|
return expect(html).toBe('BA')
|
||||||
|
})
|
||||||
|
it('should allow double quotes', async function () {
|
||||||
|
const src = 'B{% # that"s %}A'
|
||||||
|
const html = await liquid.parseAndRender(src)
|
||||||
|
return expect(html).toBe('BA')
|
||||||
|
})
|
||||||
it('should handle hash without trailing whitespace', async function () {
|
it('should handle hash without trailing whitespace', async function () {
|
||||||
const src = '{% #some comment %}'
|
const src = '{% #some comment %}'
|
||||||
const html = await liquid.parseAndRender(src)
|
const html = await liquid.parseAndRender(src)
|
||||||
|
|||||||
Reference in New Issue
Block a user