output asked headers in the order they were asked; avoid header name spoofing by...
[hband-tools.git] / user-tools / htmlentities
blob423fb5e68246c3c4c7128e163bcda9abaabbb64d
1 #!/usr/bin/env perl
3 use HTML::Entities;
4 use utf8;
5 use Getopt::Long;
7 $unsafe_control = 1;
8 $unsafe_meta = 1;
9 $unsafe_highbit = 1;
11 GetOptions(
12 'control!' => \$unsafe_control,
13 'meta!' => \$unsafe_meta,
14 'highbit!' => \$unsafe_highbit,
15 ) or die "Usage: $0 [--[no-]control] [--[no-]meta] [--[no-]highbit]\n";
17 $unsafe_chars = '';
19 if($unsafe_control) {
20 $unsafe_chars .= "\x00-\x08\x11\x12\x14-\x1F";
22 if($unsafe_meta) {
23 $unsafe_chars .= "><&\"'";
25 if($unsafe_highbit) {
26 $unsafe_chars .= "\x7F-\x{FFFFFFFF}";
29 binmode STDIN, ":utf8";
30 binmode STDOUT, ":utf8";
31 while(<>)
33 print encode_entities($_, $unsafe_chars);
36 __END__
38 =pod
40 =head1 NAME
42 htmlentities - Convert plain text into HTML-safe text
44 =head1 OPTIONS
46 =over 4
48 =item --[no-]control
50 escape control chars (0x00-0x1F except TAB, LF, and CR)
52 =item --[no-]meta
54 escape meta chars (less-than, greater-than, ampersand, double- and single-quote)
56 =item --[no-]highbit
58 scape non-ASCII chars
60 =back
62 =cut