diff --git a/4dev/tests/Convert/CoreLibsConvertJsonTest.php b/4dev/tests/Convert/CoreLibsConvertJsonTest.php index cdfc74a1..0363357f 100644 --- a/4dev/tests/Convert/CoreLibsConvertJsonTest.php +++ b/4dev/tests/Convert/CoreLibsConvertJsonTest.php @@ -277,6 +277,38 @@ final class CoreLibsConvertJsonTest extends TestCase ); } + /** + * Check if invalid flag throws exception + * + * @covers ::jsonValidate + * @testdox jsonValidate test exception thrown on invalid flag + * + * @return void + */ + public function testJsonValidateInvalidFlag(): void + { + $this->expectException("\InvalidArgumentException"); + \CoreLibs\Convert\Json::jsonValidate('{"valid": "json"}', 5); + } + + /** + * Check if valid flag throws no exception + * + * @covers ::jsonValidate + * @testdox jsonValidate test no exception on valid flag + * + * @return void + */ + public function testJsonValidateValidflag(): void + { + $this->assertTrue( + \CoreLibs\Convert\Json::jsonValidate('{"valid": "json"}', 0) + ); + $this->assertTrue( + \CoreLibs\Convert\Json::jsonValidate('{"valid": "json"}', JSON_INVALID_UTF8_IGNORE) + ); + } + /** * Undocumented function * diff --git a/www/lib/CoreLibs/Combined/DateTime.php b/www/lib/CoreLibs/Combined/DateTime.php index dab0658e..18e66190 100644 --- a/www/lib/CoreLibs/Combined/DateTime.php +++ b/www/lib/CoreLibs/Combined/DateTime.php @@ -133,7 +133,7 @@ class DateTime } else { for ($i = 0, $iMax = count($timegroups); $i < $iMax; $i++) { $output = floor((float)$timestamp / $timegroups[$i]); - $timestamp = (float)$timestamp % $timegroups[$i]; + $timestamp = $timestamp % $timegroups[$i]; // output has days|hours|min|sec if ($output || $time_string) { $time_string .= $output . $labels[$i] . (($i + 1) != count($timegroups) ? ' ' : ''); @@ -453,7 +453,7 @@ class DateTime } if (isset($matches[11]) && is_numeric($matches[11])) { // for milliseconds, we need to divide by 1000 and add them - $timestamp += (float)($matches[11] / 1000); + $timestamp += ((float)$matches[11] / 1000); } if ($negative) { // cast to float so we can do a negative multiplication diff --git a/www/lib/CoreLibs/Convert/Byte.php b/www/lib/CoreLibs/Convert/Byte.php index a9ddbd99..651d70f5 100644 --- a/www/lib/CoreLibs/Convert/Byte.php +++ b/www/lib/CoreLibs/Convert/Byte.php @@ -154,7 +154,7 @@ class Byte if (!empty($matches[1])) { $number_negative = true; } - if (isset($matches[2]) && isset($matches[3])) { + if (isset($matches[2])) { // remove all non valid characters from the number $number = preg_replace('/[^0-9\.]/', '', $matches[2]); // final clean up and convert to float diff --git a/www/lib/CoreLibs/Convert/Color/Color.php b/www/lib/CoreLibs/Convert/Color/Color.php index 016d71af..02dca1e2 100644 --- a/www/lib/CoreLibs/Convert/Color/Color.php +++ b/www/lib/CoreLibs/Convert/Color/Color.php @@ -957,9 +957,9 @@ class Color * Undocumented function * * @param HWB $hwb - * @return Lch + * @return LCH */ - public static function hwbToLch(HWB $hwb): Lch + public static function hwbToLch(HWB $hwb): LCH { return self::rgbToLch( self::hwbToRgb($hwb) @@ -1078,10 +1078,10 @@ class Color /** * OkLab to Lch (CIE) * - * @param LAB $lab + * @param Lab $lab * @return LCH */ - public static function okLabToLch(LAB $lab): LCH + public static function okLabToLch(Lab $lab): LCH { return self::labToLch( self::okLabToLab($lab) @@ -1092,9 +1092,9 @@ class Color * Lch (CIE) to OkLab * * @param LCH $lch - * @return LAB + * @return Lab */ - public static function lchToOkLab(LCH $lch): LAB + public static function lchToOkLab(LCH $lch): Lab { return self::labToOkLab( self::lchToLab($lch) diff --git a/www/lib/CoreLibs/Convert/Json.php b/www/lib/CoreLibs/Convert/Json.php index 32c42364..bddbcae2 100644 --- a/www/lib/CoreLibs/Convert/Json.php +++ b/www/lib/CoreLibs/Convert/Json.php @@ -74,11 +74,15 @@ class Json * Weill set the internval last error state and info can be read with jsonGetLastError * * @param string $json - * @param int $flags only JSON_INVALID_UTF8_IGNORE is currently allowed + * @param int $flags only JSON_INVALID_UTF8_IGNORE is currently allowed * @return bool + * @throws \InvalidArgumentException if flags is invalid */ public static function jsonValidate(string $json, int $flags = 0): bool { + if ($flags != 0 && $flags != JSON_INVALID_UTF8_IGNORE) { + throw new \InvalidArgumentException("For flag only 0 or JSON_INVALID_UTF8_IGNORE is allwed: " . $flags); + } $json_valid = json_validate($json, flags:$flags); self::$json_last_error = json_last_error(); return $json_valid; diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index 732d7a27..12673fc3 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -2562,21 +2562,27 @@ class IO // set field names $this->cursor_ext[$query_hash]['field_names'] = []; for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) { - $this->cursor_ext[$query_hash]['field_names'][] = - $this->db_functions->__dbFieldName( + if ( + ($field_name = $this->db_functions->__dbFieldName( $this->cursor_ext[$query_hash]['cursor'], $i - ); + )) !== false + ) { + $this->cursor_ext[$query_hash]['field_names'][] = $field_name; + } } $this->field_names = $this->cursor_ext[$query_hash]['field_names']; // field types $this->cursor_ext[$query_hash]['field_types'] = []; for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) { - $this->cursor_ext[$query_hash]['field_types'][] = - $this->db_functions->__dbFieldType( + if ( + ($field_type = $this->db_functions->__dbFieldType( $this->cursor_ext[$query_hash]['cursor'], $i - ); + )) !== false + ) { + $this->cursor_ext[$query_hash]['field_types'][] = $field_type; + } } $this->field_types = $this->cursor_ext[$query_hash]['field_types']; // combined name => type diff --git a/www/lib/CoreLibs/Output/Form/Elements.php b/www/lib/CoreLibs/Output/Form/Elements.php index 6fbd38ed..7f25e122 100644 --- a/www/lib/CoreLibs/Output/Form/Elements.php +++ b/www/lib/CoreLibs/Output/Form/Elements.php @@ -178,11 +178,11 @@ class Elements "/(href=\")?(\>)?\b($protRegex)([\w\.\-?&=+%#~,;\/]+)\b([\.\-?&=+%#~,;\/]*)(\|([^\||^#]+)(#([^\|]+))?\|)?/", function ($matches) { return self::createUrl( - $matches[1] ?? '', - $matches[2] ?? '', - $matches[3] ?? '', - $matches[4] ?? '', - $matches[5] ?? '', + $matches[1], + $matches[2], + $matches[3], + $matches[4], + $matches[5], $matches[7] ?? '', $matches[9] ?? '' );