feat: relativeReference for render/include/layout, #395

- `relativeReference` is enabled by default, set to `false` to disable
- Referenced files are still constrained within root/partias/layouts
- fix: relative filenames are not constrained (which allows arbitrary filesystem read)

Example Usage:

{% render "../foo/bar.html" %}

Note:

../foo/bar.html' should also be within `partials` (or `root` if `partials` not set)
This commit is contained in:
Harttle
2021-10-06 17:36:37 +08:00
parent 24a19c092a
commit a3455ebd0b
15 changed files with 160 additions and 31 deletions
+4 -4
View File
@@ -64,11 +64,11 @@ export class Liquid {
return toValue(this._parseAndRender(html, scope, true))
}
public _parsePartialFile (file: string, sync?: boolean) {
return this.parser.parseFile(file, sync, LookupType.Partials)
public _parsePartialFile (file: string, sync?: boolean, currentFile?: string) {
return this.parser.parseFile(file, sync, LookupType.Partials, currentFile)
}
public _parseLayoutFile (file: string, sync?: boolean) {
return this.parser.parseFile(file, sync, LookupType.Layouts)
public _parseLayoutFile (file: string, sync?: boolean, currentFile?: string) {
return this.parser.parseFile(file, sync, LookupType.Layouts, currentFile)
}
public async parseFile (file: string): Promise<Template[]> {
return toPromise(this.parser.parseFile(file, false))