fix(isByteLength): default min to 0 in the legacy positional signature#2791
Open
greymoth-jp wants to merge 1 commit into
Open
fix(isByteLength): default min to 0 in the legacy positional signature#2791greymoth-jp wants to merge 1 commit into
greymoth-jp wants to merge 1 commit into
Conversation
The backwards-compatibility branch assigned min = arguments[1] with no
default, so omitting min (e.g. isByteLength('abc') or
isByteLength(str, undefined, max)) left min undefined and made the final
len >= min check evaluate as len >= NaN, which is always false. The object
branch already defaults min to 0, the README documents the default as
{ min: 0 }, and the sibling isLength uses arguments[1] || 0 in the same
legacy branch.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2791 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2587 2587
Branches 656 657 +1
=========================================
Hits 2587 2587 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
isByteLengthaccepts two signatures: the object formisByteLength(str, { min, max })and the legacy positional formisByteLength(str, min, max).The object branch defaults
minto 0 (options.min || 0), but the legacy branch usedmin = arguments[1]with no default. Whenminis omitted there, it staysundefined, so the finallen >= mincheck becomeslen >= NaNand always returnsfalse.The README documents the default as
{ min: 0, max: undefined }, and the siblingisLengthalready usesarguments[1] || 0in the same legacy branch, so this only affectedisByteLength.Before:
isByteLength('abc')returnedfalseisByteLength('abc', undefined, 3)returnedfalseAfter, both return
true, matchingisByteLength('abc', { max: 3 })which was already correct.Added a case to the existing deprecated-api test block, mirroring the
{ max: 3 }object test that was already there.Checklist