Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions src/filters/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function * filter<T extends object> (this: FilterImpl, include: boolean, arr: T[
const values: unknown[] = []
arr = toArray(arr)
this.context.memoryLimit.use(arr.length)
const token = new Tokenizer(stringify(property)).readScopeValue()
const token = new Tokenizer(stringify(property), this.liquid).readScopeValue()
for (const item of arr) {
values.push(yield evalToken(token, this.context.spawn(item)))
}
Expand Down Expand Up @@ -166,7 +166,7 @@ export function * reject_exp<T extends object> (this: FilterImpl, arr: T[], item
export function * group_by<T extends object> (this: FilterImpl, arr: T[], property: string): IterableIterator<unknown> {
const map = new Map()
arr = toEnumerable(arr)
const token = new Tokenizer(stringify(property)).readScopeValue()
const token = new Tokenizer(stringify(property), this.liquid).readScopeValue()
this.context.memoryLimit.use(arr.length)
for (const item of arr) {
const key = yield evalToken(token, this.context.spawn(item))
Expand All @@ -192,7 +192,7 @@ export function * group_by_exp<T extends object> (this: FilterImpl, arr: T[], it
}

function * search<T extends object> (this: FilterImpl, arr: T[], property: string, expected: string): IterableIterator<unknown> {
const token = new Tokenizer(stringify(property)).readScopeValue()
const token = new Tokenizer(stringify(property), this.liquid).readScopeValue()
const array = toArray(arr)
const matcher = expectedMatcher.call(this, expected)
for (let index = 0; index < array.length; index++) {
Expand Down
6 changes: 5 additions & 1 deletion src/liquid-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export interface LiquidOptions {
renderLimit?: number;
/** For DoS handling, limit new objects creation, including array concat/join/strftime, etc. A typical PC can handle 1e9 (1G) memory without issue. */
memoryLimit?: number;
/** Allow parenthesized expressions as operands in conditions and loops, e.g. `{% if (foo | upcase) == "BAR" %}`. This is a non-standard extension to Liquid. Defaults to `false`. */
groupedExpressions?: boolean;
}

export interface RenderOptions {
Expand Down Expand Up @@ -162,6 +164,7 @@ export interface NormalizedFullOptions extends NormalizedOptions {
parseLimit: number;
renderLimit: number;
memoryLimit: number;
groupedExpressions: boolean;
}

export const defaultOptions: NormalizedFullOptions = {
Expand Down Expand Up @@ -197,7 +200,8 @@ export const defaultOptions: NormalizedFullOptions = {
operators: defaultOperators,
memoryLimit: Infinity,
parseLimit: Infinity,
renderLimit: Infinity
renderLimit: Infinity,
groupedExpressions: false
}

export function normalize (options: LiquidOptions): NormalizedFullOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Parser {
public parse (html: string, filepath?: string): Template[] {
html = String(html)
this.parseLimit.use(html.length)
const tokenizer = new Tokenizer(html, this.liquid.options.operators, filepath)
const tokenizer = new Tokenizer(html, this.liquid, this.liquid.options.operators, filepath)
const tokens = tokenizer.readTopLevelTokens(this.liquid.options)
return this.parseTokens(tokens)
}
Expand Down
Loading
Loading