Skip to content

Commit

Permalink
yamlDecode: Nur Array zurückliefern (#5508)
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Jan 12, 2023
1 parent eb9f48c commit aec5703
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 0 additions & 6 deletions .tools/psalm/baseline.xml
Expand Up @@ -5717,12 +5717,6 @@
<MixedFunctionCall occurrences="1">
<code>$func($value, $key)</code>
</MixedFunctionCall>
<MixedInferredReturnType occurrences="1">
<code>array</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>Symfony\Component\Yaml\Yaml::parse($value)</code>
</MixedReturnStatement>
<MixedReturnTypeCoercion occurrences="2">
<code>$result</code>
<code>string[]</code>
Expand Down
12 changes: 11 additions & 1 deletion redaxo/src/core/lib/util/string.php
Expand Up @@ -153,11 +153,21 @@ public static function yamlEncode(array $value, $inline = 3)
*/
public static function yamlDecode($value)
{
if ('' === $value) {
return [];
}

try {
return Symfony\Component\Yaml\Yaml::parse($value);
$result = Symfony\Component\Yaml\Yaml::parse($value);
} catch (Symfony\Component\Yaml\Exception\ParseException $exception) {
throw new rex_yaml_parse_exception($exception->getMessage(), $exception);
}

if (!is_array($result)) {
throw new rex_yaml_parse_exception(__FUNCTION__.' does not support YAML content containing a single scalar value (given "'.$value.'")');
}

return $result;
}

/**
Expand Down

0 comments on commit aec5703

Please sign in to comment.