-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathurldecode
executable file
·47 lines (40 loc) · 925 Bytes
/
urldecode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/urldecode
#
# Very basic wrapper script to en/de-code html/url encoded text
#
# symlink to this file, and change the name to reflect the function
#
$_ = $0;
if ( (m/url/i) || (m/uri/i) ) {
if (m/encode/i) {
use URI::Escape;
while(<>) {
print uri_escape($_);
}
} else {
while(<>) {
# print uri_unescape($_);
$_ =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
print "$_";
}
}
} elsif ( (m/html/i) ) {
use HTML::Entities;
if (m/encode/i) {
while(<>) {
print encode_entities($_);
}
} else {
while(<>) {
print decode_entities($_);
}
}
} else {
print "Unknown applet: [url|uri|html][encode|decode] are supported only\n";
exit 1
}
exit 0;