From 7631b7a49eb7595b7dcfae1d5cd38e5d11bf1b06 Mon Sep 17 00:00:00 2001 From: "[1000i100] Millicent Billette" <git@1000i100.fr> Date: Sun, 1 Jan 2023 22:56:05 +0100 Subject: [PATCH] v3.5.7 FIX: dictionary-tree don't remove empty case to handle "(|a)" and similar cases. --- CHANGELOG.fr.md | 7 ++++++- npm/package.json | 2 +- src/dictionary-parser.test.mjs | 2 +- src/dictionary-tree.mjs | 10 +++++----- src/dictionary.test.mjs | 4 ++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.fr.md b/CHANGELOG.fr.md index 241bf64..959292c 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.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)". + ## [Version 3.5.6] - 2023-01-01 (par [1000i100]) ### Corrections - dictionary-parser génère désormais correctement les variantes désaccentuées et majuscule/minuscule, sans couplage entre identifiant secret et mot de passe. @@ -152,8 +156,9 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0 - intégration des librairies de crypto nécessaires - calcul de la clef publique correspondant à chaque combinaison de secrets saisie, et comparaison à la clef publique de référence. -[Non-publié/Non-Stabilisé]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.5.6...main +[Non-publié/Non-Stabilisé]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.5.7...main +[Version 3.5.7]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.5.6...v3.5.7 [Version 3.5.6]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.5.5...v3.5.6 [Version 3.5.5]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.5.4...v3.5.5 [Version 3.5.4]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.5.3...v3.5.4 diff --git a/npm/package.json b/npm/package.json index d9c0264..03044c7 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "g1lib", - "version": "3.5.6", + "version": "3.5.7", "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.test.mjs b/src/dictionary-parser.test.mjs index 36f364c..11a4cae 100644 --- a/src/dictionary-parser.test.mjs +++ b/src/dictionary-parser.test.mjs @@ -86,7 +86,7 @@ e@@(f|g) (a|b) (c|d) h@@(i|j) -`), '((a|b|c|d)@@(a|b|c|d)|e@@(f|g)|h@@(i|j))'); +`), '((|a|b|c|d)@@(|a|b|c|d)|e@@(f|g)|h@@(i|j))'); }); test('add @@ on part without it', t => { t.is(app.parse(`(a@@b|c)`), '(a@@b|c@@c)'); diff --git a/src/dictionary-tree.mjs b/src/dictionary-tree.mjs index b820759..7d17541 100644 --- a/src/dictionary-tree.mjs +++ b/src/dictionary-tree.mjs @@ -134,7 +134,7 @@ export function splitAround(pattern,treeStruct){ const subPart = recSplitter(subTree); if(subPart.matching) { isMatch++; - if (subPart.notMatching) isAlt = true; + if (typeof subPart.notMatching !== 'undefined') isAlt = true; serialized+=subPart.matching; altSerialized+=subPart.notMatching; } else { @@ -152,8 +152,8 @@ export function splitAround(pattern,treeStruct){ const notMatching = []; treeStruct.alt.forEach(subTree=>{ const subPart = recSplitter(subTree); - if(subPart.matching) matching.push(subPart.matching); - if(subPart.notMatching) notMatching.push(subPart.notMatching); + if(typeof subPart.matching !== 'undefined') matching.push(subPart.matching); + if(typeof subPart.notMatching !== 'undefined') notMatching.push(subPart.notMatching); }) if(matching.length && notMatching.length) return {matching: `(${matching.join('|')})`,notMatching: `(${notMatching.join('|')})`} if(matching.length) return {matching: `(${matching.join('|')})`} @@ -162,8 +162,8 @@ export function splitAround(pattern,treeStruct){ throw new Error(`Error: how to splitAround ${pattern} with ${JSON.stringify(treeStruct)}`); } const res = recSplitter(treeStruct); - if(res.matching) res.matching = rawSerialize(buildTreeStruct(res.matching)); - if(res.notMatching) res.notMatching = rawSerialize(buildTreeStruct(res.notMatching)); + if(typeof res.matching !== 'undefined') res.matching = rawSerialize(buildTreeStruct(res.matching)); + if(typeof res.notMatching !== 'undefined') res.notMatching = rawSerialize(buildTreeStruct(res.notMatching)); return res; } export function serialize(treeStruct) { diff --git a/src/dictionary.test.mjs b/src/dictionary.test.mjs index 5be5678..f59bff4 100644 --- a/src/dictionary.test.mjs +++ b/src/dictionary.test.mjs @@ -201,3 +201,7 @@ test(`"aa" with default settings & a speed should generate alt including "Aa@@AA for(let i=0;i<dico.length;i++) dico.splitGet(i); t.is(dico.cache['Aa@@AA'][0], 2); }); +test(`"(|a)" with idSecPwd:true should have 4 cases`, t => { + const dico = new app.Dictionary('(|a)',{idSecPwd:true}); + t.is(dico.length, 4); +}); -- GitLab