Content deleted Content added
→Reuse Module:IP: use isIpOrRange |
→Protected edit request on 3 February 2022: new section |
||
Line 92:
{{#invoke:convert/tester|compare|IPAddress}}
:<code>isIpOrRange</code> could be used to determine if given text (with the perhaps too lenient checking of [[Module:IP]]) is a valid IP or range. Then, if it contains <code>/</code> it's a range, and if it contains <code>:</code> it's IPv6. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 05:09, 1 June 2021 (UTC)
== Protected edit request on 3 February 2022 ==
{{edit fully-protected|Module:IPAddress|answered=no}}
<code>p.isIpOrRange</code> currently requires a frame and prevents other modules (which may not have the first argument as the string to check) from checking if a given object is an IP or range. Please change lines 46 to 59 with the following.
<syntaxhighlight line start="49" lang="lua">
function p._isIpOrRange(s)
local modip = require('Module:IP')
local success, ip = pcall(modip.IPAddress.new, s)
if success then
return 'ip'
end
success, ip = pcall(modip.Subnet.new, s)
if success then
return 'range'
end
return ''
end
function p.isIpOrRange(frame)
-- {{#invoke:IPAddress|isIpOrRange|x}} → 'ip' (IPv4/IPv6) or 'range' (CIDR IPv4/IPv6) or '' (invalid)
return p._isIpOrRange(input(frame))
end
</syntaxhighlight> <span style="background:#ffff55">'''''[[User:Chlod|Chlod]]'''''</span> <small style="font-size:calc(1em - 2pt)">([[User talk:Chlod|say hi!]])</small> 17:43, 3 February 2022 (UTC)
|