diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 2e7c75c51..4ef8b83eb 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -12,7 +12,8 @@ export default function isLength(str, options) { min = arguments[1] || 0; max = arguments[2]; } + const presentationSequences = str.match(/(\uFE0F|\uFE0E)/g) || []; const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; - const len = str.length - surrogatePairs.length; + const len = str.length - presentationSequences.length - surrogatePairs.length; return len >= min && (typeof max === 'undefined' || len <= max); } diff --git a/test/validators.js b/test/validators.js index 16fb6b89b..d49cbc8bb 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4586,6 +4586,11 @@ describe('Validators', () => { validator: 'isLength', valid: ['a', '', 'asds'], }); + test({ + validator: 'isLength', + args: [{ max: 8 }], + valid: ['👩🦰👩👩👦👦🏳️🌈', '⏩︎⏩︎⏪︎⏪︎⏭︎⏭︎⏮︎⏮︎'], + }); }); it('should validate strings by byte length', () => {