When the length of the returned text of the callback is longer than the
max, the slicing of the input text, should not go into a endless loop.
Without this change, the added unit tests would fail as a result of
the infinite loop.
Bug: 41450
Change-Id: Iad84522659ab160e18828cbfc463db83bc7e4795
// Chop off characters from the end of the "inserted content" string
// until the limit is statisfied.
if ( fn ) {
- while ( $.byteLength( fn( inpParts.join( '' ) ) ) > byteLimit ) {
+ // stop, when there is nothing to slice - bug 41450
+ while ( $.byteLength( fn( inpParts.join( '' ) ) ) > byteLimit && inpParts[1].length > 0 ) {
inpParts[1] = inpParts[1].slice( 0, -1 );
}
} else {
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;