diff --git a/src/fs/loader.ts b/src/fs/loader.ts index 70eb45f4c..c1b7f8970 100644 --- a/src/fs/loader.ts +++ b/src/fs/loader.ts @@ -45,7 +45,7 @@ export class Loader { if (!enforceRoot || referenced.startsWith(dir)) { // the relatively referenced file is within one of root dirs yield referenced - return + break } } } diff --git a/test/integration/liquid/liquid.ts b/test/integration/liquid/liquid.ts index 69b20bff7..2adf9d712 100644 --- a/test/integration/liquid/liquid.ts +++ b/test/integration/liquid/liquid.ts @@ -113,6 +113,30 @@ describe('Liquid', function () { expect(str).to.equal('foo') }) }) + describe('#parse', function () { + it('should resolve relative partials', function () { + const engine = new Liquid({ + root: ['/'], + extname: '.html' + }) + mock({ + '/root/partial.html': 'foo' + }) + const tpls = engine.parse('{% render "./partial.html" %}', '/root/index.html') + return expect(engine.renderSync(tpls)).to.equal('foo') + }) + it('should resolve against pwd for relative filepath', function () { + const engine = new Liquid({ + root: ['/'], + extname: '.html' + }) + mock({ + [`${process.cwd()}/partial.html`]: 'foo' + }) + const tpls = engine.parse('{% render "./partial.html" %}', './index.html') + return expect(engine.renderSync(tpls)).to.equal('foo') + }) + }) describe('#parseFileSync', function () { it('should throw with lookup list when file not exist', function () { const engine = new Liquid({ diff --git a/test/unit/fs/loader.ts b/test/unit/fs/loader.ts index 54da91365..63eddeba6 100644 --- a/test/unit/fs/loader.ts +++ b/test/unit/fs/loader.ts @@ -7,10 +7,10 @@ use(chaiAsPromised) describe('fs/loader', function () { describe('.candidates()', function () { - it('should break once found', async function () { + it('should resolve relatively', async function () { const loader = new Loader({ relativeReference: true, fs, extname: '' } as any) const candidates = [...loader.candidates('./foo/bar', ['/root', '/root/foo'], '/root/current', true)] - expect(candidates.join()).to.equal('/root/foo/bar') + expect(candidates).to.contain('/root/foo/bar') }) }) })