Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: harttle/liquidjs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v10.6.0
Choose a base ref
...
head repository: harttle/liquidjs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v10.6.1
Choose a head ref
  • 5 commits
  • 13 files changed
  • 3 contributors

Commits on Feb 22, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    pflorek Patrick Florek
    Copy the full SHA
    d4e519c View commit details

Commits on Mar 2, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    pflorek Patrick Florek
    Copy the full SHA
    42d2590 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    pflorek Patrick Florek
    Copy the full SHA
    9c0dc5f View commit details
  3. style: fix code style

    harttle committed Mar 2, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    771b9b9 View commit details
  4. chore(release): 10.6.1 [skip ci]

    ## [10.6.1](v10.6.0...v10.6.1) (2023-03-02)
    
    ### Bug Fixes
    
    * [expression] apply value equal for arrays, [#589](#589) ([9c0dc5f](9c0dc5f))
    * strip_html for multi line <script>/<style>/comments, [#70](#70) ([42d2590](42d2590))
    semantic-release-bot committed Mar 2, 2023
    Copy the full SHA
    14e059c View commit details
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [10.6.1](https://github.com/harttle/liquidjs/compare/v10.6.0...v10.6.1) (2023-03-02)


### Bug Fixes

* [expression] apply value equal for arrays, [#589](https://github.com/harttle/liquidjs/issues/589) ([9c0dc5f](https://github.com/harttle/liquidjs/commit/9c0dc5fa39a31d477a5c5a2c5212034174bf0516))
* strip_html for multi line <script>/<style>/comments, [#70](https://github.com/harttle/liquidjs/issues/70) ([42d2590](https://github.com/harttle/liquidjs/commit/42d25902e855d3c06d5ead071bf55604f495c205))

# [10.6.0](https://github.com/harttle/liquidjs/compare/v10.5.0...v10.6.0) (2023-02-22)


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
[![npm version](https://img.shields.io/npm/v/liquidjs.svg?logo=npm&style=flat-square)](https://www.npmjs.org/package/liquidjs)
[![npm downloads](https://img.shields.io/npm/dm/liquidjs.svg?style=flat-square)](https://www.npmjs.org/package/liquidjs)
[![Coverage](https://img.shields.io/coveralls/harttle/liquidjs.svg?style=flat-square)](https://coveralls.io/github/harttle/liquidjs?branch=master)
[![Build Status](https://img.shields.io/github/workflow/status/harttle/liquidjs/Check/master.svg?style=flat-square)](https://github.com/harttle/liquidjs/actions/workflows/check.yml?query=branch%3Amaster)
[![Build Status](https://img.shields.io/github/actions/workflow/status/harttle/liquidjs/check.yml?branch=master&style=flat-square)](https://github.com/harttle/liquidjs/actions/workflows/check.yml?query=branch%3Amaster)
[![DUB license](https://img.shields.io/dub/l/vibe-d.svg?style=flat-square)](https://github.com/harttle/liquidjs/blob/master/LICENSE)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/harttle/liquidjs)

5 changes: 5 additions & 0 deletions docs/themes/navy/layout/partial/all-contributors.swig
Original file line number Diff line number Diff line change
@@ -56,6 +56,11 @@
<td align="center"><a href="https://github.com/tbdrz"><img src="https://avatars.githubusercontent.com/u/50599116?v=4?s=100" width="100px;" alt=""/></a></td>
<td align="center"><a href="http://santialbo.com"><img src="https://avatars.githubusercontent.com/u/1557563?v=4?s=100" width="100px;" alt=""/></a></td>
<td align="center"><a href="https://github.com/YahangWu"><img src="https://avatars.githubusercontent.com/u/12295975?v=4?s=100" width="100px;" alt=""/></a></td>
<td align="center"><a href="https://github.com/hongl-1"><img src="https://avatars.githubusercontent.com/u/101576612?v=4?s=100" width="100px;" alt=""/></a></td>
<td align="center"><a href="https://github.com/zxx-457"><img src="https://avatars.githubusercontent.com/u/114141362?v=4?s=100" width="100px;" alt=""/></a></td>
<td align="center"><a href="https://github.com/prassie"><img src="https://avatars.githubusercontent.com/u/1357831?v=4?s=100" width="100px;" alt=""/></a></td>
<td align="center"><a href="http://slavv.com/"><img src="https://avatars.githubusercontent.com/u/713329?v=4?s=100" width="100px;" alt=""/></a></td>
<td align="center"><a href="http://www.orgflow.io/"><img src="https://avatars.githubusercontent.com/u/3889090?v=4?s=100" width="100px;" alt=""/></a></td>
</tr>
</table>

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liquidjs",
"version": "10.6.0",
"version": "10.6.1",
"description": "A simple, expressive and safe Shopify / Github Pages compatible template engine in pure JavaScript.",
"main": "dist/liquid.node.cjs.js",
"module": "dist/liquid.node.esm.js",
4 changes: 1 addition & 3 deletions src/filters/date.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { toValue, stringify, isString, isNumber, TimezoneDate, LiquidDate, strftime, isNil } from '../util'
import { FilterImpl } from '../template'

const DEFAULT_FMT = '%A, %B %-e, %Y at %-l:%M %P %z'

export function date (this: FilterImpl, v: string | Date, format?: string, timezoneOffset?: number | string) {
const opts = this.context.opts
let date: LiquidDate
v = toValue(v)
format = toValue(format)
if (isNil(format)) format = opts.dateFormat ?? DEFAULT_FMT
if (isNil(format)) format = opts.dateFormat
else format = stringify(format)
if (v === 'now' || v === 'today') {
date = new Date()
2 changes: 1 addition & 1 deletion src/filters/html.ts
Original file line number Diff line number Diff line change
@@ -32,5 +32,5 @@ export function newline_to_br (v: string) {
}

export function strip_html (v: string) {
return stringify(v).replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g, '')
return stringify(v).replace(/<script[\s\S]*?<\/script>|<style[\s\S]*?<\/style>|<.*?>|<!--[\s\S]*?-->/g, '')
}
2 changes: 2 additions & 0 deletions src/liquid-options.ts
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@ export interface NormalizedFullOptions extends NormalizedOptions {
strictVariables: boolean;
ownPropertyOnly: boolean;
lenientIf: boolean;
dateFormat: string;
trimTagRight: boolean;
trimTagLeft: boolean;
trimOutputRight: boolean;
@@ -146,6 +147,7 @@ export const defaultOptions: NormalizedFullOptions = {
fs: fs,
dynamicPartials: true,
jsTruthy: false,
dateFormat: '%A, %B %-e, %Y at %-l:%M %P %z',
trimTagRight: false,
trimTagLeft: false,
trimOutputRight: false,
29 changes: 19 additions & 10 deletions src/render/operator.ts
Original file line number Diff line number Diff line change
@@ -2,23 +2,16 @@ import { isComparable } from '../drop/comparable'
import { Context } from '../context'
import { isFunction, toValue } from '../util'
import { isFalsy, isTruthy } from '../render/boolean'
import { isArray } from '../util/underscore'

export type UnaryOperatorHandler = (operand: any, ctx: Context) => boolean;
export type BinaryOperatorHandler = (lhs: any, rhs: any, ctx: Context) => boolean;
export type OperatorHandler = UnaryOperatorHandler | BinaryOperatorHandler;
export type Operators = Record<string, OperatorHandler>

export const defaultOperators: Operators = {
'==': (l: any, r: any) => {
if (isComparable(l)) return l.equals(r)
if (isComparable(r)) return r.equals(l)
return toValue(l) === toValue(r)
},
'!=': (l: any, r: any) => {
if (isComparable(l)) return !l.equals(r)
if (isComparable(r)) return !r.equals(l)
return toValue(l) !== toValue(r)
},
'==': equal,
'!=': (l: any, r: any) => !equal(l, r),
'>': (l: any, r: any) => {
if (isComparable(l)) return l.gt(r)
if (isComparable(r)) return r.lt(l)
@@ -48,3 +41,19 @@ export const defaultOperators: Operators = {
'and': (l: any, r: any, ctx: Context) => isTruthy(toValue(l), ctx) && isTruthy(toValue(r), ctx),
'or': (l: any, r: any, ctx: Context) => isTruthy(toValue(l), ctx) || isTruthy(toValue(r), ctx)
}

function equal (lhs: any, rhs: any): boolean {
if (isComparable(lhs)) return lhs.equals(rhs)
if (isComparable(rhs)) return rhs.equals(lhs)
lhs = toValue(lhs)
rhs = toValue(rhs)
if (isArray(lhs)) {
return isArray(rhs) && arrayEqual(lhs, rhs)
}
return lhs === rhs
}

function arrayEqual (lhs: any[], rhs: any[]): boolean {
if (lhs.length !== rhs.length) return false
return !lhs.some((value, i) => !equal(value, rhs[i]))
}
20 changes: 20 additions & 0 deletions test/e2e/issues.ts
Original file line number Diff line number Diff line change
@@ -390,4 +390,24 @@ describe('Issues', function () {
const html = await liquid.parseAndRender(tpl, ctx)
expect(html.trim()).to.equal('<a href="https://example.com">Lot more code here</a>')
})
it('#70 strip multiline content of <style>', async () => {
const str = `
<style type="text/css">
.test-one-line {display: none;}
</style>`
const engine = new Liquid()
const template = '{{ str | strip_html }}'
const html = await engine.parseAndRender(template, { str })
expect(html).to.match(/^\s*$/)
})
it('#589 Arrays should compare values', async () => {
const engine = new Liquid()
const template = `
{% assign people1 = "alice, bob, carol" | split: ", " -%}
{% assign people2 = "alice, bob, carol" | split: ", " -%}
{% if people1 == people2 %}true{%else%}false{% endif %}
`
const html = await engine.parseAndRender(template)
expect(html).to.contain('true')
})
})
18 changes: 18 additions & 0 deletions test/integration/filters/html.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { test } from '../../stub/render'
import { expect } from 'chai'
import { Liquid } from '../../../src/liquid'

describe('filters/html', function () {
let liquid: Liquid
beforeEach(() => {
liquid = new Liquid()
})
describe('escape', function () {
it('should escape \' and &', function () {
return test('{{ "Have you read \'James & the Giant Peach\'?" | escape }}',
@@ -43,14 +49,26 @@ describe('filters/html', function () {
return test('{{ "<!--Have you read-->Ulysses?" | strip_html }}',
'Ulysses?')
})
it('should strip multiline comments', function () {
expect(liquid.parseAndRenderSync('{{"<!--foo\r\nbar \ncoo\t \r\n -->"|strip_html}}')).to.equal('')
})
it('should strip all style tags and their contents', function () {
return test('{{ "<style>cite { font-style: italic; }</style><cite>Ulysses<cite>?" | strip_html }}',
'Ulysses?')
})
it('should strip multiline styles', function () {
expect(liquid.parseAndRenderSync('{{"<style> \n.header {\r\n color: black;\r\n}\n</style>" | strip_html}}')).to.equal('')
})
it('should strip all scripts tags and their contents', function () {
return test('{{ "<script async>console.log(\'hello world\')</script><cite>Ulysses<cite>?" | strip_html }}',
'Ulysses?')
})
it('should strip multiline scripts', function () {
expect(liquid.parseAndRenderSync('{{ "<script> \nfoo\r\nbar\n</script>" | strip_html }}')).to.equal('')
})
it('should not strip non-matched <script>', function () {
expect(liquid.parseAndRenderSync('{{ "<script></script>text<script></script>" | strip_html }}')).to.equal('text')
})
it('should strip until empty', function () {
return test('{{"<br/><br />< p ></p></ p >" | strip_html }}', '')
})
8 changes: 8 additions & 0 deletions test/unit/context/context.ts
Original file line number Diff line number Diff line change
@@ -128,6 +128,14 @@ describe('Context', function () {
ctx.push({ foo: Object.create({ bar: 'BAR' }) })
return expect(ctx.get(['foo', 'bar'])).to.equal(undefined)
})
it('should use prototype when ownPropertyOnly=false', function () {
ctx = new Context({ foo: Object.create({ bar: 'BAR' }) }, { ownPropertyOnly: false } as any)
return expect(ctx.get(['foo', 'bar'])).to.equal('BAR')
})
it('renderOptions.ownPropertyOnly should override options.ownPropertyOnly', function () {
ctx = new Context({ foo: Object.create({ bar: 'BAR' }) }, { ownPropertyOnly: false } as any, { ownPropertyOnly: true })
return expect(ctx.get(['foo', 'bar'])).to.equal(undefined)
})
it('should return undefined for Array.prototype.reduce', function () {
ctx.push({ foo: [] })
return expect(ctx.get(['foo', 'reduce'])).to.equal(undefined)
9 changes: 9 additions & 0 deletions test/unit/render/expression.ts
Original file line number Diff line number Diff line change
@@ -53,6 +53,15 @@ describe('Expression', function () {
it('should return false for "1==2"', async () => {
expect(await toPromise(create('1==2').evaluate(ctx, false))).to.equal(false)
})
it('should apply deep equal for arrays', async () => {
const ctx = new Context({
arr1: [1, 2],
arr2: [1, 2],
arr3: [1, 2, 3]
})
expect(await toPromise(create('arr1==arr2').evaluate(ctx, false))).to.equal(true)
expect(await toPromise(create('arr1==arr3').evaluate(ctx, false))).to.equal(false)
})
it('should return true for "1<2"', async () => {
expect(await toPromise(create('1<2').evaluate(ctx, false))).to.equal(true)
})