From c626119a8cfa0da308f023d6ca9fba638cedcdeb Mon Sep 17 00:00:00 2001 From: JAC - Frederic Bauer Date: Tue, 22 Dec 2020 14:53:22 +0100 Subject: [PATCH] Commit to featuring virtually the same content as the main branch received prior with updates to #4 and #5 - ConfigProcessController.php: Just as with the main branch, renamed a parameter from "downloadDenominator" to "downloadDescriptor" so it is more clear what its purpose is. - ConfigProcessLocationInfoController.php: Just as with the 3.x version, fixed an issue where locations for parameters would be edited poorly due to them residing outside the plain project structure - ParametersToFileWriter.php: Added documentation and caught issues with special characters being used as keys or within values and escaped these for more valid and proper yaml --- Controller/ConfigProcessController.php | 15 +++++------ .../ConfigProcessLocationInfoController.php | 2 +- Resources/doc/changelogs/CHANGELOG-2.x.md | 14 ++++++---- .../ParametersToFileWriter.php | 27 +++++++++++++++++-- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/Controller/ConfigProcessController.php b/Controller/ConfigProcessController.php index 7528bde..81874e4 100644 --- a/Controller/ConfigProcessController.php +++ b/Controller/ConfigProcessController.php @@ -326,33 +326,32 @@ public function removeFavourites (Request $request): Response * Allows to determine a specific list of parameters to be brought into a file representation and * made available for download by the user. * - * @param string $downloadDenominator A string which determines which parameters are supposed to be written to + * @param string $downloadDescriptor A string which determines which parameters are supposed to be written to * a file ("all_parameters" = all parameters, "favourites" = only favourites, * "[site access]" all parameters for that site access). * * @return BinaryFileResponse Returns the file which has been created through the selected parameters. */ - public function downloadParameterListAsTextFile($downloadDenominator): BinaryFileResponse + public function downloadParameterListAsTextFile($downloadDescriptor): BinaryFileResponse { try { - if ($downloadDenominator === "all_parameters") { + if ($downloadDescriptor === "all_parameters") { $resultingFile = ParametersToFileWriter::writeParametersToFile( ConfigProcessCoordinator::getProcessedParameters(), - $downloadDenominator ); - } else if ($downloadDenominator === "favourites") { + } else if ($downloadDescriptor === "favourites") { $resultingFile = ParametersToFileWriter::writeParametersToFile( FavouritesParamCoordinator::getFavourites( ConfigProcessCoordinator::getProcessedParameters() ), - $downloadDenominator + $downloadDescriptor ); } else { $resultingFile = ParametersToFileWriter::writeParametersToFile( ConfigProcessCoordinator::getParametersForSiteAccess( - $downloadDenominator + $downloadDescriptor ), - $downloadDenominator + $downloadDescriptor ); } } catch (InvalidArgumentException | Exception $error) { diff --git a/Controller/ConfigProcessLocationInfoController.php b/Controller/ConfigProcessLocationInfoController.php index 30a8213..86f9738 100644 --- a/Controller/ConfigProcessLocationInfoController.php +++ b/Controller/ConfigProcessLocationInfoController.php @@ -57,7 +57,7 @@ public function retrieveLocationsForParameter ($parameter, $withSiteAccess): Jso if ($locations) { foreach ($locations as $location => $value) { - if ($location !== "siteaccess-origin") { + if ($location !== "siteaccess-origin" && strpos($location,$this->projectDir) > -1) { $newKey = substr($location,strlen($this->projectDir)); $locations[$newKey] = $value; diff --git a/Resources/doc/changelogs/CHANGELOG-2.x.md b/Resources/doc/changelogs/CHANGELOG-2.x.md index 28e46ba..4e5dff7 100644 --- a/Resources/doc/changelogs/CHANGELOG-2.x.md +++ b/Resources/doc/changelogs/CHANGELOG-2.x.md @@ -2,22 +2,26 @@ ## 2.0.1 (xx.12.2020) -* Adapted the custom kernel boot process to make the location retrieval functionality +* Adapted the custom kernel boot process to make the location retrieval functionality available in Symfony 3.4 and Ibexa Platform 2.5 - + * Fixed that changes to the favourite parameter list via the frontend would be ignored * Fixed error in synchronous scrolling, where unique nodes would not be added to the other list (when they were the first node of the list) -* Changed differences highlighting via the url, to only start highlighting, when the entire page is already loaded and done +* Changed differences highlighting via the url, to only start highlighting, when the entire page is already loaded and done with the other javascripts - + * Improved some internal documentation * Improved config path retrieval: Now the process is able to find configuration files more effectively and easily and should be aware of every used file for configuration except for the custom bundle config - which is conducted by the bundles themselves. + which is conducted by the bundles themselves. + +* Fixed an issue where for resources outside the project structure, the paths would be + cut badly (it was tried to cut the project directory out of the path which didn't feature + the directory), leading to false paths in the frontend. ## 2.0 (11.12.2020) diff --git a/src/ConfigProcessorBundle/ParametersToFileWriter.php b/src/ConfigProcessorBundle/ParametersToFileWriter.php index 6d1cc5c..f51111c 100644 --- a/src/ConfigProcessorBundle/ParametersToFileWriter.php +++ b/src/ConfigProcessorBundle/ParametersToFileWriter.php @@ -41,7 +41,8 @@ public static function initializeFileWriter () * Writes a given associative array of parameters to a file in a yaml format. * * @param array $parametersToWrite An associative, hierarchical array of parameters. - * @param string $downloadDescriptor A string which determines whether or not the file should be limited or viewed in a specific context (favourites, site access, etc.). + * @param string $downloadDescriptor A string which determines whether or not the file should be limited to + * or viewed in a specific context (favourites, site access, etc.). * * @return string Returns the name of / the path to the file that has been created. */ @@ -63,7 +64,11 @@ public static function writeParametersToFile (array $parametersToWrite, $downloa // Start the file writing process only when the file does not already exist. if (!file_exists($targetName)) { if ($temporaryFile) { - $siteAccess = $downloadDescriptor === "favourites"? null : $downloadDescriptor; + $siteAccess = null; + if (!($downloadDescriptor === "favourites" || $downloadDescriptor === "all_parameters")) { + $siteAccess = $downloadDescriptor; + } + self::appendDataPerKey($temporaryFile,$parametersToWrite, $siteAccess); } @@ -117,13 +122,31 @@ private static function writeSubTree ($pathToFileToWriteTo, array $subTreeToWrit $parameterFollowUpIsArray = is_array($parameterFollowUp); if (!$parameterFollowUpIsArray) { + // Is the value a boolean, then create a string representation in order to allow it to be written out to yaml without issue. if (is_bool($parameterFollowUp)) { $parameterFollowUp = $parameterFollowUp? "true" : "false"; } else { + // If the special character '"' is included (which cannot be used as is in yaml) escape the character. + if ($parameterFollowUp && str_contains($parameterFollowUp,"\"")) { + $parameterFollowUp = str_replace("\"","\\\"",$parameterFollowUp); + } + + // To ensure that most characters and longer lines are properly escaped and wrapped from the start, enclose the string in quotes. $parameterFollowUp = '"'.$parameterFollowUp.'"'; } } + // Ensure that no special characters are used as parameter keys and if they are, properly escape them. + if (preg_match('/^[\'"^£$%&*()}{@#~?><,|=_+¬-]/', $parameterKey)) { + // The quote needs to be additionally escaped to be usable as a key. + if (str_contains($parameterKey,"\"")) { + $parameterKey = str_replace("\"","\\\"",$parameterKey); + } + + $parameterKey = '"'.$parameterKey.'"'; + } + + if (!$valueReached) { if ($parameterFollowUpIsArray) { self::writeMultiLineKeys (