diff --git a/CHANGELOG.md b/CHANGELOG.md index 08fe12b..4eb696f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 3.4.3 +- Bugfix: handling null values in source yaml file + ## 3.4.2 - Update uap-core diff --git a/src/Util/CodeGenerator.php b/src/Util/CodeGenerator.php index a097625..ab9af9a 100644 --- a/src/Util/CodeGenerator.php +++ b/src/Util/CodeGenerator.php @@ -25,11 +25,14 @@ public function generateArray(array $array): string return static function(string $source, array $element) use ($indentation, $multi, $createReducer) { [$key, $value] = $element; - if (is_scalar($value)) { - if ($multi) { - $source .= self::indent($indentation); - } - $source .= self::generateKey($key) . var_export($value, true); + if ($multi) { + $source .= self::indent($indentation); + } + + $source .= self::generateKey($key); + + if (is_scalar($value) || is_null($value)) { + $source .= var_export($value, true); if ($multi) { $source .= ",\n"; } @@ -37,10 +40,7 @@ public function generateArray(array $array): string return $source; } - if ($multi) { - $source .= self::indent($indentation); - } - $source .= self::generateKey($key) . "["; + $source .= "["; $nextMulti = count($value) > 1; if ($nextMulti) { $source .= "\n"; diff --git a/tests/Util/CodeGeneratorTest.php b/tests/Util/CodeGeneratorTest.php new file mode 100644 index 0000000..0afe855 --- /dev/null +++ b/tests/Util/CodeGeneratorTest.php @@ -0,0 +1,53 @@ + [[ + 'regex' => 'UaRegEx', + ]], + 'os_parsers' => [[ + 'regex' => '(Windows 10)', + 'os_replacement' => 'Windows', + 'os_v1_replacement' => '10', + ]], + 'device_parsers' => [[ + 'regex' => 'SomeDevice/', + 'brand_replacement' => 'Some', + 'device_replacement' => 'Device', + 'model_replacement' => null, + ]] + ]; + + $rawPhp = $cg->generateArray(Yaml::parse($yamlString)); + $evaluated = eval('return ' . $rawPhp); + + $this->assertSame($expected, $evaluated); + } +}