r83203 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83202‎ | r83203 | r83204 >
Date:02:11, 4 March 2011
Author:krinkle
Status:ok
Tags:
Comment:
Adding isIp-tests to MW JS Test Suite (based on IPTest.php)
* fixing a typo in variable statement (semicolon->comma, thx JSHint, browsers tend to ignore)
* Clean up comments
Modified paths:
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.js (modified) (history)
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js
@@ -69,7 +69,7 @@
7070 // Build page
7171 document.title = 'mediaWiki JavaScript library test suite - ' + mw.config.get( 'wgSiteName' );
7272 $( '#firstHeading' ).text( 'mediaWiki JavaScript library test suite' );
73 - var skinLinksText = 'Test in: ';
 73+ var skinLinksText = 'Test in: ',
7474 skinLinks = [],
7575 availableSkins = mw.config.get( 'wgAvailableSkins' ),
7676 skincode = '';
@@ -99,7 +99,7 @@
100100 // Try to roughly keep the order similar to the order in the files
101101 // or alphabetical (depending on the context)
102102
103 - // Main modules and their aliases
 103+ /** Main modules and their aliases **/
104104 mw.test.addHead( 'Main modules and their aliases' );
105105
106106 mw.test.addTest( 'typeof mediaWiki',
@@ -114,7 +114,7 @@
115115 mw.test.addTest( 'typeof $',
116116 'function (string)' );
117117
118 - // Prototype functions added by MediaWiki
 118+ /** Prototype functions added by MediaWiki **/
119119 mw.test.addHead( 'Prototype functions added by MediaWiki' );
120120
121121 mw.test.addTest( 'typeof $.trimLeft',
@@ -165,7 +165,7 @@
166166 mw.test.addTest( 'typeof $.compareObject',
167167 'function (string)' );
168168
169 - // mediawiki.js
 169+ /** mediawiki.js **/
170170 mw.test.addHead( 'mediawiki.js' );
171171
172172 mw.test.addTest( 'mw.config instanceof mw.Map',
@@ -216,7 +216,7 @@
217217 mw.test.addTest( 'typeof mw.user.anonymous()',
218218 'boolean (string)' );
219219
220 - // mediawiki.util.js
 220+ /** mediawiki.util.js **/
221221 mw.test.addHead( 'mediawiki.util.js' );
222222
223223 mw.test.addTest( 'typeof mw.util',
@@ -298,6 +298,40 @@
299299 mw.test.addTest( 'mw.util.validateEmail( "userfoo@ex-ample.org" )',
300300 'true (boolean)' );
301301
 302+ // From IPTest.php IPv6
 303+ mw.test.addTest( 'mw.util.isIPv6Address( "" )',
 304+ 'false (boolean)' );
 305+ mw.test.addTest( 'mw.util.isIPv6Address( ":fc:100::" )',
 306+ 'false (boolean)' );
 307+ mw.test.addTest( 'mw.util.isIPv6Address( "fc:100::" )',
 308+ 'true (boolean)' );
 309+ mw.test.addTest( 'mw.util.isIPv6Address( "fc:100:a:d:1:e:ac::" )',
 310+ 'true (boolean)' );
 311+ mw.test.addTest( 'mw.util.isIPv6Address( ":::" )',
 312+ 'false (boolean)' );
 313+ mw.test.addTest( 'mw.util.isIPv6Address( "::0:" )',
 314+ 'false (boolean)' );
 315+
 316+ // From IPTest.php IPv4
 317+ mw.test.addTest( 'mw.util.isIPv4Address( "" )',
 318+ 'false (boolean)' );
 319+ mw.test.addTest( 'mw.util.isIPv4Address( "...." )',
 320+ 'false (boolean)' );
 321+ mw.test.addTest( 'mw.util.isIPv4Address( "abc" )',
 322+ 'false (boolean)' );
 323+ mw.test.addTest( 'mw.util.isIPv4Address( "124.24.52" )',
 324+ 'false (boolean)' );
 325+ mw.test.addTest( 'mw.util.isIPv4Address( ".24.52.13" )',
 326+ 'false (boolean)' );
 327+ mw.test.addTest( 'mw.util.isIPv4Address( "124.24.52.13" )',
 328+ 'true (boolean)' );
 329+ mw.test.addTest( 'mw.util.isIPv4Address( "1.24.52.13" )',
 330+ 'true (boolean)' );
 331+ mw.test.addTest( 'mw.util.isIPv4Address( "74.24.52.13/20" )', // Range
 332+ 'false (boolean)' );
 333+ // @FIXME: The regex that's been in MW JS has never supported ranges but it should
 334+ // The regex is expected to return false for that reason
 335+
302336 // jQuery plugins
303337 mw.test.addHead( 'jQuery plugins' );
304338
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js
@@ -545,14 +545,14 @@
546546 );
547547 return (null !== mailtxt.match( HTML5_email_regexp ) );
548548 },
549 - // Note: borrows from IP.php
 549+ // Note: borrows from IP::isIPv4
550550 'isIPv4Address' : function( address, allowBlock ) {
551551 var block = allowBlock ? '(?:\\/(?:3[0-2]|[12]?\\d))?' : '';
552552 var RE_IP_BYTE = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[0-9]?[0-9])';
553553 var RE_IP_ADD = '(?:' + RE_IP_BYTE + '\\.){3}' + RE_IP_BYTE;
554554 return address.search( new RegExp( '^' + RE_IP_ADD + block + '$' ) ) != -1;
555555 },
556 - // Note: borrows from IP.php
 556+ // Note: borrows from IP::isIPv6
557557 'isIPv6Address' : function( address, allowBlock ) {
558558 var block = allowBlock ? '(?:\\/(?:12[0-8]|1[01][0-9]|[1-9]?\\d))?' : '';
559559 var RE_IPV6_ADD =

Status & tagging log

  NODES
Note 4