Modul:UrlCheck: Unterschied zwischen den Versionen

K
path früher abgetrennt
KKeine Bearbeitungszusammenfassung
K (path früher abgetrennt)
Zeile 8: Zeile 8:
if ( s == '' ) or ( #s > 2048 ) then return 3 end
if ( s == '' ) or ( #s > 2048 ) then return 3 end
-- limitation because of search engines or IE
-- limitation because of search engines or IE
if s:find( '%s' ) or s:find( '%c' ) or s:find( '%.%.' ) or s:find( '%.@' )
if s:find( '%s' ) or s:find( '%c' ) or s:match( '^%.' ) then return 4 end
or s:find( '@[%.%-]' ) or s:find( '%-%.' ) or s:find( '%.%-' )
or s:find( '%./' ) or s:find( '/%.' ) or s:match( '^%.' )
then return 4 end
 
-- https://max:muster@www.example.com:8080/index.html?p1=A&p2=B#ressource
-- https://max:muster@www.example.com:8080/index.html?p1=A&p2=B#ressource


Zeile 33: Zeile 30:
local topLevel = ''
local topLevel = ''
local at
local at
-- split path from host
at = s:find( '/' )
if at ~= nil then
path = s:sub( at + 1, #s )
s = s:sub( 1, at - 1 )
if not s then return 6 end
end
-- future: add path check
-- split at '/', last part: t == mw.uri.encode( t ) ?
if s:find( '%.%.' ) or s:find( '%.@' ) or s:find( '@[%.%-]' )
or s:find( '%-%.' ) or s:find( '%.%-' ) or s:find( '%./' ) or s:find( '/%.' )
then return 4 end


-- user and password
-- user and password
_,count = s:gsub( '@', '@' )
_,count = s:gsub( '@', '@' )
if count > 1 then return 6 end
if count > 1 then return 7 end
if count == 1 then
if count == 1 then
at = s:find( '@' )
at = s:find( '@' )
user = s:sub( 1, at - 1 )
user = s:sub( 1, at - 1 )
s = s:sub( at + 1, #s )
host = s:sub( at + 1, #s )
if not user or not s then return 7 end
if not user or not s then return 8 end


_,count = user:gsub( ':', ':' )
_,count = user:gsub( ':', ':' )
if count > 1 then return 8 end
if count > 1 then return 9 end
if count == 1 then
if count == 1 then
at = user:find( ':' )
at = user:find( ':' )
password = user:sub( at + 1, #user )
password = user:sub( at + 1, #user )
user = user:sub( 1, at - 1 )
user = user:sub( 1, at - 1 )
if not user or not password then return 9 end
if not user or not password then return 10 end
if #user > 64 then return 10 end
if #user > 64 then return 11 end
end
end
end
-- host and path
at = s:find( '/' )
if at ~= nil then
host = s:sub( 1, at - 1 )
path = s:sub( at + 1, #s )
if not host then return 11 end
else
else
host = s
host = s
if host == '' then return 11 end
end
end
 
if host == '' then return 6 end
-- future: add path check
-- split at '/', last part: t == mw.uri.encode( t ) ?


-- host and port
-- host and port
_,count = host:gsub( ':', ':' )
_,count = host:gsub( ':', ':' )
if count > 1 then return 13 end
if count > 1 then return 12 end
if count == 1 then
if count == 1 then
at = host:find( ':' )
at = host:find( ':' )
port = host:sub( at + 1, #host )
port = host:sub( at + 1, #host )
host = host:sub( 1, at - 1 )
host = host:sub( 1, at - 1 )
if not host or not port then return 11 end
if not host or not port then return 13 end
if ( port:match( '^[1-9]%d*$' ) == nil ) or
if ( port:match( '^[1-9]%d*$' ) == nil ) or
( tonumber( port ) > 65535 ) then return 14 end
( tonumber( port ) > 65535 ) then return 14 end
Anonymer Benutzer