Module:Sandbox/Thayts/1

local p = {}

function p.test(frame) local url = frame.args[1] local count = 0 local urlEnc = {} local delim = ""

for part in mw.text.gsplit(url, "[;/?:@&=+$,#]") do		urlEnc[#urlEnc + 1] = delim urlEnc[#urlEnc + 1] = mw.uri.encode(mw.uri.decode(part, "PATH"), "PATH") count = count + #part + 1 delim = url:sub(count, count) end return table.concat(urlEnc) end

local function split(str, del, from) local i, j

from = from or 1 i, j = str:find(del, from)

if i and j then return str:sub(1, i - 1), str:sub(j + 1), i, j	end

return str end

function p.test2(frame) local i, j, urlSplit, urlPath local url = frame.args[1] local urlPre = ""

i, j = url:find("//", 1, true)

if i == 1 or (i and i > 1 and url:sub(i - 1, i - 1) == ':') then urlSplit = {split(url, "[/?#]", j + 1)} urlPre = urlSplit[1]

if urlSplit[2] then urlPath = url:sub(urlSplit[3], urlSplit[4]) .. urlSplit[2] else urlPath = "" end else urlPath = url end

local count = 0 local pathEnc = {} local delim = ""

for part in mw.text.gsplit(urlPath, "[;/?:@&=+$,#]") do		pathEnc[#pathEnc + 1] = delim pathEnc[#pathEnc + 1] = mw.uri.encode(mw.uri.decode(part, "PATH"), "PATH") count = count + #part + 1 delim = urlPath:sub(count, count) end

return urlPre .. table.concat(pathEnc) end

return p