Skip to content

Twice escaping in default and default_if_none filters when printed variable and default value both taken from render and printed variable is undef #118

@pavelsr

Description

@pavelsr
use lib './blib/lib';
use lib './blib/arch';
use DTL::Fast;

my $x = 0;
my $z = \&DTL::Fast::html_protect;
*DTL::Fast::html_protect = sub {
    $x++;
    goto &$z;
};

my $tpl = DTL::Fast::Template->new('Hello, {{ username }}!');
warn $tpl->render({ username => '<xmp>Hello world</xmp>' });	# ok
warn $x; # 1

###

my $tpl = DTL::Fast::Template->new('Hello, {{ foo|default:username }}!');
warn $tpl->render({ foo => undef, username => '<xmp>Hello world</xmp>' }); # not ok
warn $x; # must be 2, but it's 3

###

my $tpl = DTL::Fast::Template->new('Hello, {{ foo|default_if_none:username }}!');
warn $tpl->render({ foo => undef, username => '<xmp>Hello world</xmp>' }); # not ok
warn $x; # 5

Seems like we need to make some fixes at lib/DTL/Fast/Variable.pm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions