Skip to content

Commit 1510f77

Browse files
committed
Add urldecode script
1 parent 5e1a0bf commit 1510f77

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

urldecode

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
declare hex_regex='[a-fA-F0-9]{2}'
4+
5+
declare output=""
6+
7+
read -rt .1 str
8+
9+
for ((i=0; i < ${#str}; i++)); do
10+
char="${str:i:1}"
11+
if [ "$char" = "%" ]; then
12+
hex="${str:i+1:2}"
13+
if ! grep -qE "$hex_regex" <<<"$hex"; then
14+
echo "Unreadable hex value: $hex" >&2
15+
exit 1
16+
fi
17+
printf -v char '%b' "\u${hex}" 2>/dev/null
18+
((i+=2))
19+
fi
20+
output="${output}${char}"
21+
done
22+
23+
printf '%s\n' "$output"

0 commit comments

Comments
 (0)