description: 'Pass the limit and a callback as input filter',
$input: $( '<input type="text"/>' )
.byteLimit( 6, function ( val ) {
- // Invalid title
- if ( val === '' ) {
- return '';
- }
-
+ var title = mw.Title.newFromText( String( val ) );
// Return without namespace prefix
- return new mw.Title( String( val ) ).getMain();
+ return title ? title.getMain() : '';
} ),
sample: 'User:Sample',
expected: 'User:Sample'
$input: $( '<input type="text"/>' )
.attr( 'maxlength', '6' )
.byteLimit( function ( val ) {
- // Invalid title
- if ( val === '' ) {
- return '';
- }
-
+ var title = mw.Title.newFromText( String( val ) );
// Return without namespace prefix
- return new mw.Title( String( val ) ).getMain();
+ return title ? title.getMain() : '';
} ),
sample: 'User:Sample',
expected: 'User:Sample'
description: 'Pass the limit and a callback as input filter',
$input: $( '<input type="text"/>' )
.byteLimit( 6, function ( val ) {
- // Invalid title
- if ( val === '' ) {
- return '';
- }
-
+ var title = mw.Title.newFromText( String( val ) );
// Return without namespace prefix
- return new mw.Title( String( val ) ).getMain();
+ return title ? title.getMain() : '';
} ),
sample: 'User:Example',
// The callback alters the value to be used to calculeate
expected: '1234'
} );
+ // Regression tests for bug 41450
+ byteLimitTest( {
+ description: 'Input filter of which the base exceeds the limit',
+ $input: $( '<input type="text"/>' )
+ .byteLimit( 3, function ( text ) {
+ return 'prefix' + text;
+ } ),
+ sample: simpleSample,
+ hasLimit: true,
+ limit: 6, // 'prefix' length
+ expected: ''
+ } );
+
QUnit.test( 'Confirm properties and attributes set', 4, function ( assert ) {
var $el, $elA, $elB;