r76275 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76274‎ | r76275 | r76276 >
Date:22:46, 7 November 2010
Author:aaron
Status:ok (Comments)
Tags:
Comment:
Similar to r76267 but for JS. Should finish bug 24293.
Modified paths:
  • /trunk/extensions/CheckUser/checkuser.js (modified) (history)
  • /trunk/phase3/skins/common/block.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/block.js
@@ -29,7 +29,15 @@
3030
3131 var addy = target.value;
3232 var isEmpty = addy.match(/^\s*$/);
33 - var isIp = addy.match(/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7})(\/\d+)?$/);
 33+
 34+ // @TODO: get some core JS IP functions
 35+ // Match the first IP in each list (ignore other garbage)
 36+ var isIpV4 = addy.match(/^(\d+\.\d+\.\d+\.\d+)(\/\d+)?$/);
 37+ // Regexp has 3 cases: (starts with '::',ends with '::',neither)
 38+ var isIpV6 = !addy.match(/::.*::/) // not ambiguous
 39+ && addy.match(/^(:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(::?[0-9A-Fa-f]{1,4}){0,6}::|[0-9A-Fa-f]{1,4}(::?[0-9A-Fa-f]{1,4}){1,7})(\/\d+)?$/);
 40+
 41+ var isIp = ( isIpV4 || isIpV6 );
3442 var isIpRange = isIp && addy.match(/\/\d+$/);
3543
3644 var anonymousRow = document.getElementById( 'wpAnonOnlyRow' );
Index: trunk/extensions/CheckUser/checkuser.js
@@ -41,9 +41,12 @@
4242 var invalid = false;
4343 // ...in the spirit of block.js, call this "addy"
4444 var addy = ips[i];
 45+ // @TODO: get some core JS IP functions
4546 // Match the first IP in each list (ignore other garbage)
4647 var ipV4 = addy.match(/(^|\b)(\d+\.\d+\.\d+\.\d+)(\/\d+)?\b/);
47 - var ipV6 = addy.match(/(^|\b)(:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7})(\/\d+)?\b/);
 48+ // Regexp has 3 cases: (starts with '::',ends with '::',neither)
 49+ var ipV6 = !addy.match(/::.*::/) // not ambiguous
 50+ && addy.match(/(^|\b)(:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(::?[0-9A-Fa-f]{1,4}){0,6}::|[0-9A-Fa-f]{1,4}(::?[0-9A-Fa-f]{1,4}){1,7})(\/\d+)?\b/);
4851 // Binary form
4952 var bin = new String( '' );
5053 // Convert the IP to binary form: IPv4

Follow-up revisions

RevisionCommit summaryAuthorDate
r78099*Follow-up r76275: regexp improvement akin to IP.php...aaron22:33, 8 December 2010
r78161*Follow-up r78099,r76275:...aaron00:16, 10 December 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r76267* Fixed RE_IPV6_ADD for IP networks ending in "::", like "abcd::/y" or "a::/y"...aaron20:31, 7 November 2010
r76270Made sanitizeIP() handle CIDR IPs in IPv6 (fixes server-side stuff for bug 24...aaron21:53, 7 November 2010

Comments

#Comment by Aaron Schulz (talk | contribs)   09:46, 17 November 2010

Tagging as reminder. This needs follow-up just like the core regex to remove over-inclusiveness (which was pre-existing).

Status & tagging log