Escape minus in $.escapeRE
authorKrinkle <krinkle@users.mediawiki.org>
Wed, 9 Mar 2011 21:50:00 +0000 (21:50 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Wed, 9 Mar 2011 21:50:00 +0000 (21:50 +0000)
* Follow-up r83287: Removing slash before caret(^), apparently not needed.
* Escaping minus (-), adding the minus symbol (added in r83284), causes all uppercase characters and numbers to be escaped:
(bug 27960) $.escapeRE shouldn't escape all uppercase and numbers
* Added more compelete tets to the JS Test Suite for $.escapeRE to avoid problems in the future

resources/mediawiki.util/mediawiki.util.test.js
resources/mediawiki/mediawiki.js

index f98632e..fa670bc 100644 (file)
                                                mw.test.addTest( 'typeof $.escapeRE',
                                                        'function (string)' );
 
-                                               mw.test.addTest( '$.escapeRE( ".st{e}$st" )',
-                                                       '\\.st\\{e\\}\\$st (string)' );
+                                               mw.test.addTest( '$.escapeRE( "<!-- ([{+mW+}]) $^|?>" )',
+                                                       '<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?> (string)' ); // double escaped
+
+                                               mw.test.addTest( '$.escapeRE( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" )',
+                                                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ (string)' );
+
+                                               mw.test.addTest( '$.escapeRE( "abcdefghijklmnopqrstuvwxyz" )',
+                                                       'abcdefghijklmnopqrstuvwxyz (string)' );
+
+                                               mw.test.addTest( '$.escapeRE( "0123456789" )',
+                                                       '0123456789 (string)' );
 
                                                mw.test.addTest( 'typeof $.isEmpty',
                                                        'function (string)' );
index b84a2c3..5c842cd 100644 (file)
@@ -14,7 +14,7 @@ jQuery.extend({
                return str.substr( 0, 1 ).toUpperCase() + str.substr( 1, str.length );
        },
        escapeRE : function( str ) {
-               return str.replace ( /([\\{}()|.?*+-\^$\[\]])/g, "\\$1" );
+               return str.replace ( /([\\{}()|.?*+\-^$\[\]])/g, "\\$1" );
        },
        // $.isDomElement( document.getElementById('content') ) === true
        // $.isDomElement( document.getElementsByClassName('portal') ) === false (array)