Skip to content

Commit

Permalink
Small fix featuring issues #4 and #5
Browse files Browse the repository at this point in the history
- CHANGELOG-3.x.md: Added more information on changes made

- ConfigProcessLocationInfoController.php: Fixed a small issue where paths which did not feature the project directory or were in a different path under a similar directory, would be needlessly cut, leading to false paths.

- ParametersToFileWriter.php: Added more documentation and removed a redundant symbol of a regex to improve functionality and clarity of the code.
  • Loading branch information
JAC - Frederic Bauer committed Dec 22, 2020
1 parent f32d91f commit 0ed0fd3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Controller/ConfigProcessLocationInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function retrieveLocationsForParameter (string $parameter, string $withSi

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;
Expand Down
6 changes: 5 additions & 1 deletion Resources/doc/changelogs/CHANGELOG-3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
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.

* More and more detailed documentation.
* More (and more detailed) documentation.

* 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.

## 3.0 (11.12.2020)

Expand Down
7 changes: 6 additions & 1 deletion src/ConfigProcessorBundle/ParametersToFileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,23 @@ private static function writeSubTree (string $pathToFileToWriteTo, array $subTre
$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.'"';
}
}

if (preg_match('/^[\'"^£$%&*()}{@#~?><>,|=_+¬-]/', $parameterKey)) {
// 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);
}
Expand Down

0 comments on commit 0ed0fd3

Please sign in to comment.