From b47cc1cde3cd8243a7e9ed7f648b03e5ef2793f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthijs=20Gr=C3=BCnbauer?= Date: Sun, 14 Apr 2024 15:36:01 +0200 Subject: [PATCH] Move checkTimeFormat check to CRequest class --- adagucserverEC/CDBAdapterPostgreSQL.cpp | 13 ------------- adagucserverEC/CRequest.cpp | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/adagucserverEC/CDBAdapterPostgreSQL.cpp b/adagucserverEC/CDBAdapterPostgreSQL.cpp index ec42246e..b68a5bd7 100644 --- a/adagucserverEC/CDBAdapterPostgreSQL.cpp +++ b/adagucserverEC/CDBAdapterPostgreSQL.cpp @@ -409,19 +409,6 @@ CDBStore::Store *CDBAdapterPostgreSQL::getFilesAndIndicesForDimensions(CDataSour CT::string *sDims = queryParams.splitToArray("/"); // Split up by slashes (and put into sDims) // It is allowed to pass time as a range: start/end. If we do this, we assume to given value is datetime string - // Verify if time dimension is valid - bool isTime1Valid = CServerParams::checkTimeFormat(sDims[0]); - bool isTime2Valid = true; - if (sDims->count > 1) { - isTime2Valid = CServerParams::checkTimeFormat(sDims[0]); - } - if (!isTime1Valid || !isTime2Valid) { - // FIXME: should we just print the given dimension? Also maybe datetime validation should happen outside this method - if ((CServerParams::checkDataRestriction() & SHOW_QUERYINFO) == false) query.copy("hidden"); - CDBError("queryOrderedDESC fails regular expression: '%s'", query.c_str()); - return NULL; - } - dimMap[dim->netCDFDimName.c_str()] = sDims; } diff --git a/adagucserverEC/CRequest.cpp b/adagucserverEC/CRequest.cpp index 796f5445..f39f30dd 100644 --- a/adagucserverEC/CRequest.cpp +++ b/adagucserverEC/CRequest.cpp @@ -1175,6 +1175,20 @@ int CRequest::fillDimValuesForDataSource(CDataSource *dataSource, CServerParams } } + // Check if requested time dimensions use valid characters + for (auto &dim: dataSource->requiredDims) { + // FIXME: checkTimeFormat used to get called on every dim value, not just datetime. Check if this is required + if (!dim->isATimeDimension) continue; + + CT::string *dimValues = dim->value.splitToArray(","); + for (size_t i = 0; i < dimValues->count; i++) { + if (!CServerParams::checkTimeFormat(dimValues[i])) { + CDBError("Queried dimension %s=%s failed datetime regex", dim->name.c_str(), dim->value.c_str()); + throw InvalidDimensionValue; + } + } + } + // STOP NOW } catch (int i) { CDBError("%d", i);