CLI encoder and decoder for HTML entities
A command-line tool for encoding and decoding HTML entities, similar to base64 or urlencode. Converts special characters like <, >, &, ", ' to their HTML entity equivalents (<, >, &, ", ') and vice versa.
./autogen.sh && ./configure && makeThen sudo make install to install to /usr/local/bin
gcc -Wall -Wextra -pedantic -O2 -s -o htmlencode src/main.cReads from standard input, writes to standard output.
-aencode all characters (using numeric entities)-bdo not automatically encode non printable (i.e. binary) characters-cspecify a different set of special characters when encoding-ddecode data-lencode input line by line-ndo not output the trailing newline when encoding-xuse hexadecimal entities (&#xHH;) instead of decimal (&#NNN;)-hdisplay help and exit
Encode HTML:
echo '<script>alert("XSS")</script>' | htmlencodeOutput: <script>alert("XSS")</script>
Decode HTML:
echo '<script>alert("XSS")</script>' | htmlencode -dOutput: <script>alert("XSS")</script>
Encode all characters as numeric entities:
echo "Hello" | htmlencode -aOutput: Hello
Use hex entities:
echo "<test>" | htmlencode -axOutput: <test>
- Named entities: Common characters (
<,>,&,",') are encoded as named entities by default - Numeric entities: Can encode any character as decimal (
&#NNN;) or hex (&#xHH;) numeric entities - Decode support: Full decoding of both named and numeric (decimal/hex) entities
- Line mode: Process input line by line with
-l - Binary safe: Automatically encodes non-printable characters (unless disabled with
-b)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.