Module:Sensitive IP addresses/summary: Difference between revisions

Content deleted Content added
add a cellstyle option
strip suffixes for CIDR ranges that can be represented as a single IP address
Line 3:
 
local p = {}
 
-- Strips a suffix from a CIDR string if the suffix is of a given bitLength.
-- bitLength must be either 32 or 128.
-- This is intended to allow CIDR strings to be represented as a single IP
-- address if this can be done unambiguously.
local function stripCIDRSuffix(cidr, bitLength)
assert(bitLength == 32 or bitLength == 128, 'bitLength was not 32 or 128')
local pattern = '/' .. bitLength .. '$'
cidr = cidr:gsub(pattern, '')
return cidr
end
 
-- Takes an array of CIDR ranges and returns a new array with ranges
-- appropriate for printing.
local function prettifyRanges(ranges, bitLength)
local ret = {}
for i, cidr in ipairs(ranges) do
ret[i] = stripCIDRSuffix(cidr, bitLength)
end
return ret
end
 
-- Turns an array of CIDR ranges into its string representation.
local function stringifyRanges(ranges, bitLength, separator)
if not ranges then
return ''
end
ranges = prettifyRanges(ranges, bitLength)
return table.concat(ranges, separator)
end
 
function p._table(options)
Line 65 ⟶ 95:
:tag('td')
:cssText(options.cellstyle)
:wikitext(stringifyRanges(
entityData.ipv4Ranges,
32,
and table.concat(entityData.ipv4Ranges, rangeSeparator)
or nilrangeSeparator
))
:done()
:tag('td')
:cssText(options.cellstyle)
:wikitext(stringifyRanges(
entityData.ipv6Ranges,
128,
and table.concat(entityData.ipv6Ranges, rangeSeparator)
or nilrangeSeparator
))
:done()
:tag('td')