Templa...scaping(3pm)

πŸ“¦
version 0.0303 Β· 2 versions
  • 0.0303 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.0303 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Templa...scaping(3pm) πŸ’–

okay bestie, welcome to the User Contributed Perl Documentation section, where this little page lives under the name Templa...scaping(3pm). buckle up, we're talking auto-escaping in Template-Toolkit and it's honestly iconic.


✨ NAME ✨

Template::Stash::AutoEscaping β€” escape automatically in Template-Toolkit. no cap, that's literally the whole job.


πŸ¦‹ SYNOPSIS πŸ¦‹

  use Template;
  use Template::Stash::AutoEscaping;
  my $tt = Template->new({
    STASH => Template::Stash::AutoEscaping->new
  });

look at her go πŸ’… two use lines and a STASH and you're protected.


πŸŽ€ METHODS πŸŽ€

🌸 new 🌸

she's the constructor, she takes a hashref of options, and here's the full menu:

  • die_on_unescaped β€” if you set this to a true value, the process throws an exception the moment it bumps into a value that wasn't explicitly set to be escaped, or that was marked as a raw value. drama queen behaviour, but for safety 🫢
  • escape_type β€” default is HTML.
  • method_for_escape β€” the default method used to escape a value explicitly. mostly useful alongside "die_on_unescaped".
  • method_for_raw β€” default is raw. so you can pull the not-escaped value out with [% value.raw %].
  • escape_method β€” here's how you hand her your own escaping logic:
      my $tt = Template->new({
        STASH => Template::Stash::AutoEscaping->new({
            escape_method => sub { my $text = shift; ... ; return $text }
        })
      });
  • ignore_escape β€” the escape-off switch, for when you need it:
      my $stash = Template::Stash::AutoEscaping->new({ignore_escape => [qw(include_html include_raw my_escape_func)], ... );

You can disable auto-escape for some value or TT-Macro. For example: include another component, for output-safety html, using another escape method, etc. etc. the list goes on ✨

πŸ’œ class_for πŸ’œ

  Template::Stash::AutoEscaping->class_for("HTML") # Template::Stash::AutoEscaping::Escaped::HTML
  Template::Stash::AutoEscaping->class_for("HTML" => "MyHTMLString");

two ways to call her, same energy.

🧚 escape 🧚

For internal use. (iykyk, don't touch πŸ‘‘)

🧚 escape_count 🧚

For internal use.

🧚 get 🧚

For internal use.

🧚 get_raw_args 🧚

For internal use.


πŸ”₯ DESCRIPTION πŸ”₯

Template::Stash::AutoEscaping is a sub class of Template::Stash that automatically escapes all HTML strings and avoids XSS vulnerability. that's it, that's the vibe β€” your templates stay cute and safe 🌈


⭐ CONFIGURE ⭐

  • $Template::Stash::AutoEscaping::ESCAPE_ARGS β€” default is 0. for example "key of hash" or "args of vmethods" are not escaped. I think this is good in most cases. so, [% hash.${key} %] [% hash.item(key) %] means [% hash.${key.raw} | html %] [% hash.item(key.raw) | html %] by default. periodt.

πŸ‘‘ AUTHOR πŸ‘‘

  • mala <cpan@ma.la> β€” original author of Template::Stash::AutoEscape
  • Shlomi Fish (<http://www.shlomifish.org/>) β€” added some enhancements and fixes, while disclaiming all rights, as part of his work for <http://reask.com/> and released the result as "Template::Stash::AutoEscaping".

πŸ’€ SEE ALSO πŸ’€

  • Template
  • Template::Stash::EscapedHTML
  • Template::Stash::AutoEscape

go read those too, bestie, they're all part of the fam 🫢


🌸 LICENSE 🌸

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's a wrap πŸ’– this page shipped as part of perl v5.34.0, dated 2022-06-17, filed under Templa...scaping(3pm). slay, go escape some HTML, ily πŸŽ€βœ¨

πŸ“¦ where this page comes from