From c6422e79c70a369beb74e78d0794452d15f86210 Mon Sep 17 00:00:00 2001 From: "[1000i100] Millicent Billette" <git@1000i100.fr> Date: Thu, 12 Jan 2023 14:21:06 +0100 Subject: [PATCH] v3.5.8 FIX: dictionary-parser no more create duplicate with variable qty operator. example: "A{0,5}" --- CHANGELOG.fr.md | 4 ++++ npm/package.json | 2 +- src/dictionary-parser.mjs | 11 ++++++++--- src/dictionary-parser.test.mjs | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.fr.md b/CHANGELOG.fr.md index 959292c..114377f 100644 --- a/CHANGELOG.fr.md +++ b/CHANGELOG.fr.md @@ -14,6 +14,10 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0 ## [Non-publié/Non-Stabilisé] (par [1000i100]) +## [Version 3.5.8] - 2023-01-12 (par [1000i100]) +### Corrections +- dictionary-parser ne génère plus de doublon superflu lorsque des quantités variables sont indiquées ( comme "A{0,5}" par exemple) + ## [Version 3.5.7] - 2023-01-01 (par [1000i100]) ### Corrections - dictionary-tree ne supprime plus les alternatives vides ce qui permet d'avoir le comportement attendu avec des chaines comme "(|a)". diff --git a/npm/package.json b/npm/package.json index 03044c7..973ba3f 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "g1lib", - "version": "3.5.7", + "version": "3.5.8", "description": "An ubiquitous static javascript toolbox lib for Ǧ1 / Duniter ecosystem with reliability in mind.", "main": "nodejs/all.mjs", "browser": "browser/all.mjs", diff --git a/src/dictionary-parser.mjs b/src/dictionary-parser.mjs index 277f56d..af28831 100644 --- a/src/dictionary-parser.mjs +++ b/src/dictionary-parser.mjs @@ -209,11 +209,16 @@ function bracketsHandler(theString) { return theString; } function qtyHandlerReplaceCallback(all, chr, qty) { - const mm = qty.split(',').map(n => n.trim() * 1); // eslint-disable-line no-implicit-coercion + const mm = qty.split(',').map(n => parseInt(n.trim())); const min = mm[0]; const max = (mm.length === 2) ? mm[1] : min; - let result = new Array(min + 1).join(chr);// eslint-disable-line unicorn/no-new-array - for (let i = min; i < max; i++) result += `(|${chr})`; + if(isNaN(min) || isNaN(max)) throw `Error, invalid quantity : ${qty}`; + let result = chr.repeat(min); + if(max>min){ + result+='('; + for (let i = 0; i <= max-min; i++) result += `|${chr.repeat(i)}`; + result+=')'; + } return result; } function qtyHandler(theString) { diff --git a/src/dictionary-parser.test.mjs b/src/dictionary-parser.test.mjs index 11a4cae..00b543c 100644 --- a/src/dictionary-parser.test.mjs +++ b/src/dictionary-parser.test.mjs @@ -34,10 +34,10 @@ test('parse handle {qty}', t => { t.is(app.parse('a{5}',{idSecPwd:false}), 'aaaaa'); }); test('parse handle {min,max}', t => { - t.is(app.parse('b{3,5}',{idSecPwd:false}), 'bbb(|b)(|b)'); + t.is(app.parse('b{3,5}',{idSecPwd:false}), 'bbb(|b|bb)'); }); test('parse handle (string){qty}', t => { - t.is(app.parse(`c'est (toto|tata){0,2}`,{idSecPwd:false}), `c'est (|tata|toto)(|tata|toto)`); + t.is(app.parse(`c'est (toto|tata){0,2}`,{idSecPwd:false}), `c'est ((tata|toto)(tata|toto)||tata|toto)`); }); test('parse handle nested (s|t(ri|ng)){qty}', t => { t.is(app.parse(`(s|t(ri|ng)){1,2}`,{idSecPwd:false}), `(t(ng|ri)|s)(t(ng|ri)||s)`); -- GitLab