From a074b32dc892c3d0c48bd9cc99012dbb8e5822aa Mon Sep 17 00:00:00 2001 From: greymoth <246701683+greymoth-jp@users.noreply.github.com> Date: Tue, 30 Jun 2026 08:50:41 +0900 Subject: [PATCH] fix(isByteLength): default min to 0 in the legacy positional signature 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. --- src/lib/isByteLength.js | 2 +- test/validators.test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/isByteLength.js b/src/lib/isByteLength.js index 619d7f604..99f0d25ad 100644 --- a/src/lib/isByteLength.js +++ b/src/lib/isByteLength.js @@ -9,7 +9,7 @@ export default function isByteLength(str, options) { min = options.min || 0; max = options.max; } else { // backwards compatibility: isByteLength(str, min [, max]) - min = arguments[1]; + min = arguments[1] || 0; max = arguments[2]; } const len = encodeURI(str).split(/%..|./).length - 1; diff --git a/test/validators.test.js b/test/validators.test.js index 9c867efae..610e76605 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -5727,6 +5727,12 @@ describe('Validators', () => { valid: [''], invalid: ['g', 'a'], }); + test({ + validator: 'isByteLength', + args: [undefined, 3], + valid: ['abc', 'de', 'g', 'a', ''], + invalid: ['abcd', 'gm'], + }); });