jenkins-bot has submitted this change and it was merged.

Change subject: Introduce mediawiki.RegExp module
......................................................................


Introduce mediawiki.RegExp module

Simple module based on the $.escapeRE method of the old
"jquery.mwExtension" module.

Change-Id: I9e108a3f8c24d87bb239b63a14807a691c25aa3e
---
M maintenance/jsduck/categories.json
M resources/Resources.php
A resources/src/mediawiki/mediawiki.RegExp.js
M tests/qunit/QUnitTestResources.php
A tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js
5 files changed, 67 insertions(+), 0 deletions(-)

Approvals:
  Gilles: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/jsduck/categories.json 
b/maintenance/jsduck/categories.json
index 7e73e64..96c05a1 100644
--- a/maintenance/jsduck/categories.json
+++ b/maintenance/jsduck/categories.json
@@ -23,6 +23,7 @@
                                "classes": [
                                        "mw.Title",
                                        "mw.Uri",
+                                       "mw.RegExp",
                                        "mw.messagePoster.*",
                                        "mw.notification",
                                        "mw.Notification_",
diff --git a/resources/Resources.php b/resources/Resources.php
index c280770..0f2fc94 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1020,6 +1020,10 @@
                'scripts' => 'resources/src/mediawiki/mediawiki.notify.js',
                'targets' => array( 'desktop', 'mobile' ),
        ),
+       'mediawiki.RegExp' => array(
+               'scripts' => 'resources/src/mediawiki/mediawiki.RegExp.js',
+               'targets' => array( 'desktop', 'mobile' ),
+       ),
        'mediawiki.pager.tablePager' => array(
                'styles' => 
'resources/src/mediawiki/mediawiki.pager.tablePager.less',
                'position' => 'top',
diff --git a/resources/src/mediawiki/mediawiki.RegExp.js 
b/resources/src/mediawiki/mediawiki.RegExp.js
new file mode 100644
index 0000000..1da4ab4
--- /dev/null
+++ b/resources/src/mediawiki/mediawiki.RegExp.js
@@ -0,0 +1,22 @@
+( function ( mw ) {
+       /**
+        * @class mw.RegExp
+        */
+       mw.RegExp = {
+               /**
+                * Escape string for safe inclusion in regular expression
+                *
+                * The following characters are escaped:
+                *
+                *     \ { } ( ) | . ? * + - ^ $ [ ]
+                *
+                * @since 1.26
+                * @static
+                * @param {string} str String to escape
+                * @return {string} Escaped string
+                */
+               escape: function ( str ) {
+                       return str.replace( /([\\{}()|.?*+\-\^$\[\]])/g, '\\$1' 
);
+               }
+       };
+}( mediaWiki ) );
diff --git a/tests/qunit/QUnitTestResources.php 
b/tests/qunit/QUnitTestResources.php
index 9093797..c6f3a23 100644
--- a/tests/qunit/QUnitTestResources.php
+++ b/tests/qunit/QUnitTestResources.php
@@ -66,6 +66,7 @@
                        
'tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js',
                        
'tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js',
                        
'tests/qunit/suites/resources/mediawiki/mediawiki.messagePoster.factory.test.js',
+                       
'tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js',
                        
'tests/qunit/suites/resources/mediawiki/mediawiki.template.test.js',
                        
'tests/qunit/suites/resources/mediawiki/mediawiki.test.js',
                        
'tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js',
@@ -108,6 +109,7 @@
                        'mediawiki.api.watch',
                        'mediawiki.jqueryMsg',
                        'mediawiki.messagePoster',
+                       'mediawiki.RegExp',
                        'mediawiki.Title',
                        'mediawiki.toc',
                        'mediawiki.Uri',
diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js 
b/tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js
new file mode 100644
index 0000000..2388497
--- /dev/null
+++ b/tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js
@@ -0,0 +1,38 @@
+( function ( mw, $ ) {
+       QUnit.module( 'mediawiki.RegExp' );
+
+       QUnit.test( 'escape', 16, function ( assert ) {
+               var specials, normal;
+
+               specials = [
+                       '\\',
+                       '{',
+                       '}',
+                       '(',
+                       ')',
+                       '[',
+                       ']',
+                       '|',
+                       '.',
+                       '?',
+                       '*',
+                       '+',
+                       '-',
+                       '^',
+                       '$'
+               ];
+
+               normal = [
+                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
+                       'abcdefghijklmnopqrstuvwxyz',
+                       '0123456789'
+               ].join( '' );
+
+               $.each( specials, function ( i, str ) {
+                       assert.propEqual( str.match( new RegExp( 
mw.RegExp.escape( str ) ) ), [ str ], 'Match ' + str );
+               } );
+
+               assert.equal( mw.RegExp.escape( normal ), normal, 
'Alphanumerals are left alone' );
+       } );
+
+}( mediaWiki, jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/219562
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9e108a3f8c24d87bb239b63a14807a691c25aa3e
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Edokter <er...@darcoury.nl>
Gerrit-Reviewer: Gilles <gdu...@wikimedia.org>
Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to