From 8fc6502a89702437a846604aecc7f0b24b529489 Mon Sep 17 00:00:00 2001 From: hamou Date: Tue, 26 Nov 2024 11:19:49 +0100 Subject: [PATCH 1/2] Fix fetching visualisation fields --- src/app/services/visualize.service.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/services/visualize.service.ts b/src/app/services/visualize.service.ts index c83d3639..7cbb8454 100644 --- a/src/app/services/visualize.service.ts +++ b/src/app/services/visualize.service.ts @@ -73,7 +73,13 @@ export class VisualizeService { public getVisuFields(urlTemplate): string[] { if (urlTemplate.indexOf('{') >= 0) { - const fields = urlTemplate.split(/[{}]/).filter(v => v.length > 0); + /** Fetch all elements between {} in the template. */ + const regex = new RegExp(/{([^}]+)}/g); + const fields = []; + let match; + while ((match = regex.exec(urlTemplate)) !== null) { + fields.push(match[1]); + } if (fields) { return fields .filter(f => f !== 'x') From d79b1f94bc3724b05805c8267708dc6e1f002a87 Mon Sep 17 00:00:00 2001 From: hamou Date: Tue, 26 Nov 2024 11:42:36 +0100 Subject: [PATCH 2/2] avoid a while loop to prevent infinite loop --- src/app/services/visualize.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/services/visualize.service.ts b/src/app/services/visualize.service.ts index 7cbb8454..83489075 100644 --- a/src/app/services/visualize.service.ts +++ b/src/app/services/visualize.service.ts @@ -76,9 +76,9 @@ export class VisualizeService { /** Fetch all elements between {} in the template. */ const regex = new RegExp(/{([^}]+)}/g); const fields = []; - let match; - while ((match = regex.exec(urlTemplate)) !== null) { - fields.push(match[1]); + const matches = [...urlTemplate.matchAll(regex)]; + if (!!matches) { + matches.filter(m => !!m && Array.isArray(m) && m.length > 1).forEach(m => fields.push(m[1])); } if (fields) { return fields