From b275e604c13004427e37cc1f42139d2f412158f2 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Tue, 1 Mar 2016 00:15:34 +0200 Subject: templatelayout.cpp: fix potential issue in preprocessTemplate() The function preprocessTemplate(), did not account well for indexes in Grantlee variables, such as: dive.weight# (where # is the index) dive.cylinder# To solve the issue the list (QList >) for variables to be replaced is populated will all possible indexes: 0 - MAX_WEIGHTSYSTEM for weights 0 - MAX_CYLINDERS for cylinders Signed-off-by: Lubomir I. Ivanov Signed-off-by: Dirk Hohndel --- desktop-widgets/templatelayout.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'desktop-widgets/templatelayout.cpp') diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp index 34443b9c1..fd0a44c75 100644 --- a/desktop-widgets/templatelayout.cpp +++ b/desktop-widgets/templatelayout.cpp @@ -55,18 +55,24 @@ TemplateLayout::~TemplateLayout() */ static QString preprocessTemplate(const QString &in) { + int i; QString out = in; - + QString iStr; QList > list; - list << qMakePair(QString("dive.weight"), QString("dive.weights.")); + + /* populate known variables in a QPair list */ list << qMakePair(QString("dive.weights"), QString("dive.weightList")); - list << qMakePair(QString("dive.cylinder"), QString("dive.cylinders.")); + for (i = 0; i < MAX_WEIGHTSYSTEMS; i++) + list << qMakePair(QString("dive.weight%1").arg(i), QString("dive.weights.%1").arg(i)); + list << qMakePair(QString("dive.cylinders"), QString("dive.cylinderList")); + for (i = 0; i < MAX_CYLINDERS; i++) + list << qMakePair(QString("dive.cylinder%1").arg(i), QString("dive.cylinders.%1").arg(i)); /* lazy method of variable replacement without regex. the Grantlee parser * works with a single or no space next to the variable markers - * e.g. '{{ var }}' */ - for (int i = 0; i < list.length(); i++) { + for (i = 0; i < list.length(); i++) { QPair p = list.at(i); out.replace("{{ " + p.first + " }}", "{{ " + p.second + " }}"); out.replace("{{" + p.first + "}}", "{{" + p.second + "}}"); -- cgit v1.2.3-70-g09d2