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

Change subject: jquery.byteLimit: Fix infinite loop if text is longer than max
......................................................................


jquery.byteLimit: Fix infinite loop if text is longer than max

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
---
M resources/jquery/jquery.byteLimit.js
M tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js
2 files changed, 15 insertions(+), 1 deletion(-)

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



diff --git a/resources/jquery/jquery.byteLimit.js 
b/resources/jquery/jquery.byteLimit.js
index f2b98f0..a8c0b06 100644
--- a/resources/jquery/jquery.byteLimit.js
+++ b/resources/jquery/jquery.byteLimit.js
@@ -78,7 +78,8 @@
                // 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 {
diff --git a/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js 
b/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js
index 7f4494e..596c57c 100644
--- a/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js
@@ -184,6 +184,19 @@
                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;
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iad84522659ab160e18828cbfc463db83bc7e4795
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Matmarex <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to