From abd630e81bc150d05e4129cc22752ecf461777c7 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 11 May 2023 14:39:19 +0200 Subject: Allow all hierarchical path segments to be ['...'] quoted ...and not just set elements. "tdf#104005 Don't allow changing finalized properties" found that some existing property names include "/", which makes them unusable with e.g. getPropertyByHierarchicalName. The most obvious solution is to allow ['...'] quoting (without a leading template name, though) for all kinds of hierarchical path segments. (In theory, that would cause backwards incompatibility, as e.g. a property named ['foo'] could no longer be referenced by a ['foo'] path segment (it would need to be referenced by a ['['foo']'] path segment instead). But in practice, that path segment ['foo'] would have been rejected in the past anyway, as it did not reference a set element.) To make this work, the meaning of the setElement out-parameter of configmgr::Data::parseSegment is changed to only be true if the segment uses ['...'] notation including a leading (non-empty) template name. What this change does not (yet) address is writing out such quoted (group or set) names in the hierarchical paths written out in configmgr::writeModFile, where necessary. (It never writes out names of properties as parts of hierarchical names, so this wouldn't be an issue for the existing problematic properties containing "/" in their names, anyway.) Change-Id: I635d823c7bbb6b8ac5869c7e0130ba8cfd329599 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151673 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- configmgr/qa/unit/test.cxx | 23 +++++++++++++++++------ configmgr/source/data.cxx | 11 +++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/configmgr/qa/unit/test.cxx b/configmgr/qa/unit/test.cxx index 60d19be8472c..aa5b137413d3 100644 --- a/configmgr/qa/unit/test.cxx +++ b/configmgr/qa/unit/test.cxx @@ -205,12 +205,23 @@ void Test::setUp() void Test::testKeyFetch() { - OUString s; - CPPUNIT_ASSERT( - getKey( - "/org.openoffice.System", - "L10N/Locale") >>= - s); + { + OUString s; + CPPUNIT_ASSERT( + getKey( + "/org.openoffice.System", + "L10N/Locale") >>= + s); + } + { + auto const v = getKey( + "/org.openoffice.Office.Embedding", + "MimeTypeClassIDRelations/['application/vnd.sun.xml.report.chart']"); + OUString s; + CPPUNIT_ASSERT(v >>= s); + CPPUNIT_ASSERT_EQUAL(OUString("80243D39-6741-46C5-926E-069164FF87BB"), s); + // cf. officecfg/registry/data/org/openoffice/Office/Embedding.xcu + } } void Test::testKeySet() diff --git a/configmgr/source/data.cxx b/configmgr/source/data.cxx index 24987d65c44b..b0cad8042962 100644 --- a/configmgr/source/data.cxx +++ b/configmgr/source/data.cxx @@ -124,10 +124,14 @@ sal_Int32 Data::parseSegment( *setElement = false; return i; } - if (templateName != nullptr) { - if (i - index == 1 && path[index] == '*') { + if (i - index == 1 && path[index] == '*') { + *setElement = true; + if (templateName != nullptr) { templateName->clear(); - } else { + } + } else { + *setElement = i != index; + if (templateName != nullptr) { *templateName = path.copy(index, i - index); } } @@ -144,7 +148,6 @@ sal_Int32 Data::parseSegment( { return -1; } - *setElement = true; return j + 2; } -- cgit