Changed _template_content() to fail on PROCESSing directory to prevent cache corruption #12

Merged
merged 3 commits into from Jan 25, 2013

2 participants

@colinmkeith

lib/Template/Provider.pm: _template_content() now fails on opening directories.

open() does not fail, but acts like directory is an empty file, so when caching is enabled the PROCESS'ed template is created, without error, as a 0b files in the cache folder. This means that templates within that folder can't have cache files created because the template directory structure is used in the cache.

E.g. If I have template/profiles/user.tmpl and accidentally PROCESS 'profiles' then a 0b file is created in the cache under the name "profiles". Accordingly when I PROCESS 'profiles/user.tmpl' then the cache can't write to cachedir/profiles/user.tmpl because cachedir/profiles is a file not a directory.

PROCESS'ing a directory doesn't make sense so it should fail as an error.

Also changed _load() to use $error returned from _template_content(). This allows the caller to understand the error instead of getting back "$alias: $!". In the case of PROCESS'ing a directory we explicitly test with -d so there is no error set in $!, and it defaults to the meaningless "No such file or directory" instead of the error message that we defined ('not a file')

colinmkeith and others added some commits Jul 7, 2012
@colinmkeith colinmkeith lib/Template/Provider.pm: _template_content() Should fail on opening …
…directories. open() does not fail, but acts like directory is an empty file. When caching is enabled this silently creates 0b files in cache folder which causes templates from within the folder to fail to create cache files. Tweaked _load() to use $error returned from _template_content() instead of using ignoring it and using hardcoded error. Added t/process_dir.t to test for these issues
1e32f9f
gitolite tester text_split(): Set the line number on which a directive occurs to excl…
…ude the white space leading up to it as this is not prefix text and is stripped and so not available as a TEXT or LITERAL tokens
775c337
gitolite tester text_split(): Set the line number on which a directive occurs to excl…
…ude the white space leading up to it as this is not prefix text and is stripped and so not available as a TEXT or LITERAL tokens
e8e0d1c
@abw abw merged commit 4cc7df3 into abw:master Jan 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment