Modul:URLutil: Unterschied zwischen den Versionen
2016-01-01
w>PerfektesChaos (2015-12-05) |
w>PerfektesChaos (2016-01-01) |
||
| Zeile 1: | Zeile 1: | ||
local URLutil = { suite = "URLutil", | local URLutil = { suite = "URLutil", | ||
serial = " | serial = "2016-01-01" }; | ||
--[=[ | --[=[ | ||
Utilities for URL etc. on www. | Utilities for URL etc. on www. | ||
| Zeile 78: | Zeile 78: | ||
if type( url ) == "string" then | if type( url ) == "string" then | ||
local colon, host, port | local colon, host, port | ||
local pattern = "^%s*%w*:?//([%w%.%%-]+)(:?)([%d]*)/" | local pattern = "^%s*%w*:?//([%w%.%%_-]+)(:?)([%d]*)/" | ||
local s = mw.text.decode( url ) | local s = mw.text.decode( url ) | ||
local i = s:find( "#", 6, true ) | local i = s:find( "#", 6, true ) | ||
| Zeile 345: | Zeile 345: | ||
local r | local r | ||
if type( s ) == "string" then | if type( s ) == "string" then | ||
local pattern = "^%s*([%w%.%%-]+)(:?)(%d*)%s*$" | local pattern = "^%s*([%w%.%%_-]+)(:?)(%d*)%s*$" | ||
local host, colon, port = mw.ustring.match( s, pattern ) | local host, colon, port = mw.ustring.match( s, pattern ) | ||
if colon == ":" then | if colon == ":" then | ||
| Zeile 367: | Zeile 367: | ||
local r | local r | ||
if type( s ) == "string" then | if type( s ) == "string" then | ||
local scan = "^%s*([%w%.%%-]+%w)%.(%a[%w-]*%a)%s*$" | local scan = "^%s*([%w%.%%_-]+%w)%.(%a[%w-]*%a)%s*$" | ||
local scope | local scope | ||
s, scope = mw.ustring.match( s, scan ) | s, scope = mw.ustring.match( s, scan ) | ||
| Zeile 594: | Zeile 594: | ||
if URLutil.getAuthority( url ) then | if URLutil.getAuthority( url ) then | ||
if not url:match( "%S%s+%S" ) then | if not url:match( "%S%s+%S" ) then | ||
return true | local s1, s2 = url:match( "^([^#]+)(#.*)$" ) | ||
if s2 then | |||
if url:match( "^%s*[a-zA-Z]*://(.+)/" ) then | |||
return true | |||
end | |||
else | |||
return true | |||
end | |||
end | end | ||
end | end | ||
| Zeile 608: | Zeile 615: | ||
local s = URLutil.getAuthority( url ) | local s = URLutil.getAuthority( url ) | ||
local pat = "[%[|%]" .. | local pat = "[%[|%]" .. | ||
mw.ustring.char( 8201, 45, 8207, 8234, 45, 8239, 8288 ) | mw.ustring.char( 8201, 45, 8207, | ||
8234, 45, 8239, | |||
8288 ) | |||
.. "]" | .. "]" | ||
if s:find( "@" ) | if s:find( "@" ) | ||