diff --git a/CHANGELOG.fr.md b/CHANGELOG.fr.md index 959292c4f44e63f92ad0e28c3452f51d9eca1546..114377fa340d2d4fc76fc0714d21bc212e96c06b 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 03044c7d9cc9434b67ebb134ccbc768e988a146e..973ba3fd8dad31ec06610ac2ea9af240bc6aabc1 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 277f56d76e989513230ff0f3b5bae4d5526636ce..af2883197dd98b80dfe189a47d9c6719ea81a63a 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 11a4cae5aec9939ac8cb55f79b2cd1eb01b42641..00b543c9f40dc4321aec4fbb672e0058e5ed9ae9 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)`);