|
|
Choosing A Webhost: |
Re: option to turn ESCAPE=HTML on by default: msg#00023lang.perl.modules.html-template
* Roger Burton West <roger@xxxxxxxxxxxxx> [October 17 2005, 07:10]: > >my $template = HTML::Template->new(filename=>'filename.tmpl', > >html_escape=>1); > > Orthogonality, please: > escape => 'html' > > just as we have ESCAPE=HTML in the templates. One name, one function, please :) default_escape => 'html'. Patch below, with tests. diff -ruN /tmp/HTML-Template-2.7/Template.pm HTML-Template-2.7/Template.pm --- /tmp/HTML-Template-2.7/Template.pm Fri Jun 18 21:42:06 2004 +++ HTML-Template-2.7/Template.pm Mon Oct 17 14:43:36 2005 @@ -955,6 +955,7 @@ no_includes => 0, case_sensitive => 0, filter => [], + default_template => undef, ); # load in options supplied to new() @@ -1076,6 +1077,12 @@ $self->{cache} = \%cache; } + if ($options->{default_escape}) { + unless ($options->{default_escape} =~ s/^(html|url|js)$/uc($1)/ie) { + croak("Wrong default_escape specified: \"$options->{default_escape}\"."); + } + } + print STDERR "### HTML::Template Memory Debug ### POST CACHE INIT ", $self->{proc_mem}->size(), "\n" if $options->{memory_debug}; @@ -1952,7 +1959,7 @@ $which = uc($1); # which tag is it - $escape = defined $5 ? $5 : defined $15 ? $15 : 0; # escape set? + $escape = defined $5 ? $5 : defined $15 ? $15 : defined $options->{default_escape} ? $options->{default_escape} : 0; # escape set? # what name for the tag? undef for a /tag at most, one of the # following three will be defined diff -ruN /tmp/HTML-Template-2.7/t/99-old-test-pl.t HTML-Template-2.7/t/99-old-test-pl.t --- /tmp/HTML-Template-2.7/t/99-old-test-pl.t Fri Jun 18 21:34:59 2004 +++ HTML-Template-2.7/t/99-old-test-pl.t Mon Oct 17 14:54:18 2005 @@ -795,7 +795,7 @@ ok($output =~ /I AM INNER 2/); # test javascript escaping -$template = $template = HTML::Template->new(path => ['templates'], +$template = HTML::Template->new(path => ['templates'], filename => 'js.tmpl'); $template->param(msg => qq{"He said 'Hello'.\n\r"}); $output = $template->output(); @@ -807,3 +807,24 @@ }; like($@, qr/empty filename/); +# test default escaping +$template = HTML::Template->new(path => ['templates'], + filename => 'default_escape.tmpl', + default_escape => 'UrL'); +$template->param(STUFF => q{Joined with space}); +$output = $template->output(); +is($output, q{Joined%20with%20space} . "\n"); + +$template = HTML::Template->new(path => ['templates'], + filename => 'default_escape.tmpl', + default_escape => 'html'); +$template->param(STUFF => q{Joined&with"cruft}); +$output = $template->output(); +is($output, q{Joined&with"cruft} . "\n"); + +eval { +$template = HTML::Template->new(path => ['templates'], + filename => 'default_escape.tmpl', + default_escape => 'wml'); +}; +like($@, qr/Wrong default_escape/); diff -ruN /tmp/HTML-Template-2.7/templates/default_escape.tmpl HTML-Template-2.7/templates/default_escape.tmpl --- /tmp/HTML-Template-2.7/templates/default_escape.tmpl Thu Jan 1 03:00:00 1970 +++ HTML-Template-2.7/templates/default_escape.tmpl Mon Oct 17 14:47:39 2005 @@ -0,0 +1 @@ +<TMPL_VAR STUFF> -- Alex Kapranoff, $n=["1another7Perl213Just3hacker49"=~/\d|\D*/g]; $$n[0]={grep/\d/,@$n};print"@$n{1..4}\n" ------------------------------------------------------- This SF.Net email is sponsored by: Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: option to turn ESCAPE=HTML on by default, Roger Burton West |
|---|---|
| Next by Date: | Re: option to turn ESCAPE=HTML on by default, Sam Tregar |
| Previous by Thread: | Re: option to turn ESCAPE=HTML on by default, Roger Burton West |
| Next by Thread: | Re: option to turn ESCAPE=HTML on by default, Sam Tregar |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |