From 95345ae0c778848bac8a4e545ac454c302941f49 Mon Sep 17 00:00:00 2001 From: ikkyu-3 Date: Sun, 15 May 2022 12:19:40 +0900 Subject: [PATCH] fix(isLength) added process to subtract Presentation Sequences characters --- src/lib/isLength.js | 3 ++- test/validators.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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', () => {