Parser(3pm)

πŸ“¦
version 1.03 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Parser(3pm) πŸ’–

okay bestie, sit down, grab your matcha 🍡 β€” this is HTML::StripScripts::Parser, an XSS filter that rides on top of HTML::Parser, and it's lowkey iconic. She's part of the Perl user-contributed docs, she's giving security-but-make-it-cute, and she's about to eat. πŸ‘‘


✨ NAME ✨

HTML::StripScripts::Parser β€” XSS filter using HTML::Parser πŸ›‘οΈπŸ¦‹


✨ SYNOPSIS ✨

like, here's the whole vibe in one go:

use HTML::StripScripts::Parser();

my $hss = HTML::StripScripts::Parser->new(

     {
         Context => 'Document',       ## HTML::StripScripts configuration
         Rules   => { ... },
     },

     strict_comment => 1,             ## HTML::Parser options
     strict_names   => 1,

);

$hss->parse_file("foo.html");

print $hss->filtered_document;

OR

print $hss->filter_html($html);

see how the first hashref is all HTML::StripScripts business and the stuff after it is pure HTML::Parser energy? that's the whole concept. slay. πŸ’…


✨ DESCRIPTION ✨

So this class is the easy interface to HTML::StripScripts β€” it uses HTML::Parser to actually chew through the HTML for you. πŸ“

If you wanna know how to customise the way the raw HTML gets parsed into tags, go read HTML::Parser. And if you wanna know how to customise the way those tags get filtered, that's all HTML::StripScripts. iykyk. πŸ’œ


✨ CONSTRUCTORS ✨

new ( {CONFIG}, [PARSER_OPTIONS] )

Makes you a brand new HTML::StripScripts::Parser object. new object, who dis. ✨

  • The CONFIG parameter has the exact same semantics as the CONFIG parameter to the HTML::StripScripts constructor. same rules, same energy.
  • Any PARSER_OPTIONS you hand over get passed straight on to the HTML::Parser init method, so you can influence how the input gets parsed. πŸŽ€
⚠️ okay important, no cap: you cannot use PARSER_OPTIONS to set the HTML::Parser event handlers (peep "Events" in HTML::Parser) β€” because HTML::StripScripts::Parser is already using all of those event hooks itself. she's booked and busy. πŸ™ˆ BUT. you can use Rules (see "Rules" in HTML::StripScripts) to customise the handling of all tags and attributes. so you're not stuck, bestie. πŸ’–

✨ METHODS ✨

For input methods, go look at HTML::Parser. For output methods, go look at HTML::StripScripts. teamwork makes the dream work 🫢

filter_html()

filter_html() is the lil convenience queen πŸ‘‘ β€” she filters HTML that's already loaded into a scalar variable. Basically she's just three calls in a trench coat: HTML::Parser::parse(), HTML::Parser::eof(), and HTML::StripScripts::filtered_document(). ✨

$filtered_html = $hss->filter_html($html);

one line, zero stress, she ate. πŸ”₯


✨ SUBCLASSING ✨

The HTML::StripScripts::Parser class is subclassable β€” yes, you can make her your own. 🌈

  • Filter objects are just plain hashes. no fancy blessed struct situation, just vibes. πŸ’€
  • The hss_init() method takes the same arguments as new(), and it calls the initialization methods of both HTML::StripScripts and HTML::Parser. double the init, double the fun. πŸŽ€

Also go read "SUBCLASSING" in HTML::StripScripts and "SUBCLASSING" in HTML::Parser for the full lore. πŸ“š


✨ SEE ALSO ✨

  • HTML::StripScripts
  • HTML::Parser
  • HTML::StripScripts::LibXML

the whole friend group πŸ’–


✨ BUGS ✨

None reported. ✨ literally flawless behaviour (so far πŸ‘€).

If you do find bugs or have feature requests, please report them to bug-html-stripscripts-parser@rt.cpan.org, or slide through the web interface at <http://rt.cpan.org>. don't be shy, they wanna hear it. 🫢


✨ AUTHOR ✨

  • Original author: Nick Cleaton <nick@cleaton.net>
  • New code added and module maintained by: Clinton Gormley <clint@traveljury.com>

shoutout to the OGs πŸ«‘πŸ’œ


  • Copyright (C) 2003 Nick Cleaton. All Rights Reserved.
  • Copyright (C) 2007 Clinton Gormley. All Rights Reserved.

✨ LICENSE ✨

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. periodt. πŸ’…


and that's the whole page, bestie πŸ’– go forth and sanitise responsibly βœ¨πŸ¦‹

perl v5.32.0 Β· 2021-01-03 Β· Parser(3pm) β€” mwah, catch you in the next manpage, love u, bye πŸ‘‘πŸŽ€

πŸ“¦ where this page comes from