Skip to content

FileLoader::normalizePath() strips leading ../ #138

@spaze

Description

@spaze

First, thanks for making Latte! ☕

While migrating to Latte 2.4 I've find the following issue, if I do this in a presenter:

$this->createTemplate()->setFile('../../foo/bar.latte);

and there's

{include waldo.latte}

in bar.latte, rendering fails with

_RuntimeException: Missing template file foo/waldo.latte_

I've tracked it down to an issue in Latte\Loaders\FileLoader::normalizePath() where in the first foreach iteration when $res is still empty then if it hits $part === '..' condition then the $part is just thrown away because it tries to array_pop from an empty array.

The issue can be demonstrated by adding

Assert::same('../../tests', $loader->getReferredName('../tests', '../file'));

to Loaders.FileLoader.phpt.

Hope this is at least a bit understandable.

The workaround is to never pass leading ../ to setFile() (and use realpath() to remove these) but since I've already spent quite a while figuring out where's the problem, the proposed fix is an incoming pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions