Module:LinkParser: Difference between revisions
Created page with "-- Parses links inserted by editors in templates, strips them of the protocol part, and otherwise prints exactly what was entered to minimize spoofing local p = {} ---------------------------------- -- Remove protocol and leading www. ---------------------------------- function p.strip(link) -- Remove the protocol part: http://, https://, ftp://, etc. -- (%a+ matches one or more letters, so it will strip e.g. http, https, ftp.) link = link:gsub("^%a+://", "") -- Re..." |
No edit summary |
||
| Line 1: | Line 1: | ||
-- Parses links inserted by editors in templates, strips them of the protocol part, and otherwise | -- Parses links inserted by editors in templates, strips them of the protocol part, | ||
-- leading "www.", and any trailing "/", while otherwise printing exactly what was entered | |||
-- to minimize spoofing. | |||
local p = {} | local p = {} | ||
---------------------------------- | ---------------------------------- | ||
-- Remove protocol | -- Remove protocol, leading www., and trailing / | ||
---------------------------------- | ---------------------------------- | ||
function p.strip(link) | function p.strip(link) | ||
-- Remove the protocol part: http://, https://, ftp://, etc. | -- Remove the protocol part: http://, https://, ftp://, etc. | ||
link = link:gsub("^%a+://", "") | link = link:gsub("^%a+://", "") | ||
-- Remove leading "www." | -- Remove leading "www." | ||
link = link:gsub("^www%.", "") | link = link:gsub("^www%.", "") | ||
-- Remove trailing "/" | |||
link = link:gsub("/$", "") | |||
return link | return link | ||
end | end | ||
| Line 26: | Line 29: | ||
end | end | ||
-- Strip protocol | -- Strip protocol, leading 'www.', and trailing '/' | ||
local displayText = p.strip(rawLink) | local displayText = p.strip(rawLink) | ||