Add script for percent-escaping (and unescaping)
This commit is contained in:
parent
1328c65502
commit
8cf20e57f9
1 changed files with 22 additions and 0 deletions
22
bin/percent
Executable file
22
bin/percent
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env lua
|
||||
|
||||
local args do
|
||||
local parse = require 'arrr' {
|
||||
{ "Unescape instead of escaping", "--decode", "-d" };
|
||||
}
|
||||
args = parse{...}
|
||||
end
|
||||
|
||||
local pattern, replace
|
||||
if args.decode then
|
||||
pattern, replace = "%%%x%x", function(escape)
|
||||
return string.char(tonumber(escape:sub(2, 3), 16))
|
||||
end
|
||||
else
|
||||
pattern = "[:/?#@!$&'()*+,;=[%]%%\n ]"
|
||||
replace = function(plain)
|
||||
return string.format("%%%0X", plain:byte())
|
||||
end
|
||||
end
|
||||
|
||||
io.write((io.read("a*"):gsub(pattern, replace)))
|
Loading…
Reference in a new issue