Module talk:IPAddress: Difference between revisions

Content deleted Content added
Reuse Module:IP: needs thought
 
(14 intermediate revisions by 5 users not shown)
Line 84:
:::::Sounds good then! I have no permissions to edit this template, can any of you apply the changes in the sandbox? Is there anything that needs to be addressed before? [[User:MarioGom|MarioGom]] ([[User talk:MarioGom|talk]]) 16:44, 27 March 2021 (UTC)
::::::The thing that's outstanding is fixing the globals as mentioned above. I'll have a look at that later. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 00:50, 28 March 2021 (UTC)
:::::::I edited the sandbox to fix the globals. However I added a TODO note which is going to require quite a bit of thought because the changes (to accept ranges as noted above) might not be compatible with how this module is used. I'm not even sure if it is desirable: should 1.2.3.4/5 be regarded as a valid IPv4 address? Also, the testcases need thought. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 08:38, 28 March 2021 (UTC)
::::::::My use case is distinguishing IPv4 address/CIDR from IPv6 address/CIDR (for {{tl|Proxyip}}, {{tl|Proxyip4}}, {{tl|Proxyip6}}). I then use isIpOrRange or other methods to check if it's a range. My guess is that for any template or module using it for usernames it shouldn't make any difference. If you think the breakage risk is too high, then I would go for new functions like isIpV4AddressOrRange and isIpV6AddressOrRange. Although it can be simpler to keep it to 2 orthogonal aspects: IPv4 vs IPv6 and address vs range. [[User:MarioGom|MarioGom]] ([[User talk:MarioGom|talk]]) 14:30, 31 March 2021 (UTC)
:::::::::(disclosure: i wrote this module years ago, i think per some request in wp:vpt or wp:lua): can one of you guys, in one of the next passes, also make the functions in this module "local"? it's a bit of a sticking point... peace - [[User:קיפודנחש|קיפודנחש (aka kipod)]] ([[User talk:קיפודנחש|talk]]) 17:39, 31 March 2021 (UTC)
::::::::::I already cleaned the module and there are now no globals (in the sandbox). Some searching showed it is likely the globals are unused but we'll find out when the sandbox eventually goes live. I've been caught up off-wiki and haven't fully thought about the issue but new functions might be best. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 03:03, 1 April 2021 (UTC)
{{Outdent}} {{u|Johnuniq}}: We have two pending issues. One is whether we want a separate set of functions or not. My ''guess'' is that current usages will probably be ok with the change, but I can separate the functionality if we want to be extra safe. The other is the question of strict/lax parsing. [[Module:IPAddress]] is quite strict while [[Module:IP]] accepts many addresses that are invalid (even if they can be parsed with some assumptions). I thought about proposing a bit of stricter parsing at [[Module:IP]], like not accepting two zero compressions (::) in the same address. But I fear that following that road means it will never be done. [[User:MarioGom|MarioGom]] ([[User talk:MarioGom|talk]]) 17:18, 31 May 2021 (UTC)
:It's two months since my last comment and that's too long for me to remember what this is all about. I edited [[Module:IPAddress]] to include my changes in [[Module:IPAddress/sandbox]] relating to style and to remove global functions. That will make a comparison easier.
{{#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=yes}}
<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 string 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>&nbsp;<small style="font-size:calc(1em - 2pt)">([[User talk:Chlod|say&nbsp;hi!]])</small> 17:43, 3 February 2022 (UTC)
:This looks good, thanks. I updated [[Module:IPAddress/sandbox]] with a slightly tweaked version of the above (just a slight re-ordering to suit what is already in the module) and will do a final check a little later. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 22:47, 3 February 2022 (UTC)
::Done. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 01:01, 4 February 2022 (UTC)
:::Thank you very much! {{smiley}} <span style="background:#ffff55">'''''[[User:Chlod|Chlod]]'''''</span>&nbsp;<small style="font-size:calc(1em - 2pt)">([[User talk:Chlod|say&nbsp;hi!]])</small> 09:53, 4 February 2022 (UTC)
 
== isIpV4Range and isIpV6Range ==
 
I've created the new functions isIpV4Range and isIpV6Range which do exactly what it sounds like. This is for use in [[Template:Vandal]] but can probably come in handy in other places as well. If noone objects in the next few days I will take the code in the sandbox live. There are testcases. --[[User:Trialpears|Trialpears]] ([[User talk:Trialpears|talk]]) 18:30, 10 January 2023 (UTC)
 
:i do not see any such functions in the snadbox.
:i am guessing the functions you describe reside somewhere else. furthermore, i am guessing they are in the same vein as _isIpOrRange().
:presuming this is the case, i'll say what i should have said when this function was added: i think it's utterly silly. not the function itself, of course, but its inclusion in this module. i can't imagine what is the added value of placing in module A a function that does nothing but pipe calls to module B.
:this practice makes sense when some of the "native" functions of A are using this implanted function, but this is not the case here, and _isIpOrRange, as well as the 2 new functions you describe are entirely for "export" purposes. all they do is pipe functionality of [[Module:IP]], and my common sense says they should reside there. what is the value of planting this "foreign body" here?
:tl;dr: please consider placing these new functions in module IP rather than here.
:peace. [[User:קיפודנחש|קיפודנחש (aka kipod)]] ([[User talk:קיפודנחש|talk]]) 19:47, 10 January 2023 (UTC)
::@[[User:קיפודנחש|קיפודנחש]] [https://en.wikipedia.org/w/index.php?title=Module:IPAddress/sandbox&diff=1132811434&oldid=1069755838 Here] is a diff with the code at [[Module:IPAddress/sandbox]] and testcases at [[Module talk:IPAddress/testcases]].
::In principal I'm not opposed to having this in [[Module:IP]] instead, but if were going to have two separate modules, which the [[Wikipedia:Templates_for_discussion/Log/2018_July_1#Module:IP|2018 TfD]] thought was for the best, I feel this fits better here than in [[Module:IP]] since it's intended to be easy to use in templates while IP seems to have functions primarily intended for use in Modules. --[[User:Trialpears|Trialpears]] ([[User talk:Trialpears|talk]]) 20:22, 10 January 2023 (UTC)
:::thanks. don't know how i missed them earlier. i have some excuses, but i doubt anyone here will be interested.
:::those functions seem to be in the right place - they do use the functionality of this module, and do belong here, contrary to my previous assumption they do not, which was made before reading the code. thanks.
:::btw, the addition of these functions (retroactively) justifies the inclusion of _isIpOrRange() here...
:::will be good to add testcases, both positive and negative, before merging the sandbox to the module itself.
:::peace. [[User:קיפודנחש|קיפודנחש (aka kipod)]] ([[User talk:קיפודנחש|talk]]) 00:10, 11 January 2023 (UTC)