మాడ్యూల్:URL: కూర్పుల మధ్య తేడాలు

Content deleted Content added
చి Protected Module:URL: Highly visible template: used in Template:URL ([Edit=Block all non-admin users] (indefinite) [Move=Block all non-admin users] (indefinite))
Wrap the URL parsing in a pcall to catch errors from malformed URLs
పంక్తి 8:
function trim(s)
return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
end
 
function safeUri(s)
local success, uri = mw.uri.newpcall(function(url)
return mw.uri.new(s)
end)
if success then
return uri
end
end
 
Line 25 ⟶ 34:
url = mw.ustring.gsub(url, '%s', function(s) return mw.uri.encode(s, 'PATH') end)
-- If there is an empty query string or fragment id, remove it as it will cause mw.uri.new to throw an error
local uri = mw.uri.new(url)
url = mw.ustring.gsub(url, '#$', '')
url = mw.ustring.gsub(url, '%?$', '')
-- If it's an HTTP[S] URL without the double slash, fix it.
url = mw.ustring.gsub(url, '^[Hh][Tt][Tt][Pp]([Ss]?):(/?)([^/])', 'http%1://%3')
local uri = safeUri(url)
-- Handle URL's without a protocol, e.g. www.example.com/foo or www.example.com:8080/foo
if uri and (not uri.protocol or (uri.protocol and not uri.host)) then
url = 'http://' .. url
uri = mw.uri.newsafeUri(url)
end
if text == '' then
if uri then
if uri.path == '/' then uri.path = '' end
local port = ''
if uri.port then port = ':' .. uri.port end
text = mw.ustring.lower(uri.host or '') .. port .. (uri.relativePath or '')
else -- URL is badly-formed, so just display whatever was passed in
text = url
end
end
 
"https://te.wikipedia.org/wiki/మాడ్యూల్:URL" నుండి వెలికితీశారు