From e6b5ced3433f8930b625cab4e3bcf56b7762585e Mon Sep 17 00:00:00 2001 From: dimon Date: Wed, 23 Apr 2025 11:26:07 +0000 Subject: [PATCH] Update ParserKrokiTag.php --- ParserKrokiTag.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/ParserKrokiTag.php b/ParserKrokiTag.php index 4405464..c725d80 100644 --- a/ParserKrokiTag.php +++ b/ParserKrokiTag.php @@ -58,6 +58,12 @@ class ParserKrokiTag { 'wavedrom', 'wireviz' ]; + + /** @var string[] Output format types */ + public const OUTPUT_FORMAT_TYPES = [ + 'svg', + 'png' + ]; /** * Constructor method for MyClass. @@ -82,6 +88,16 @@ class ParserKrokiTag { private static function validDiagrammType( string $string ): bool { return in_array( strtolower( $string ), array_map( 'strtolower', self::DIAGRAM_TYPES ), true ); } + + /** + * Check if $string is one of avaliable output format extensions. + * + * @param string $string string to check + * @return bool {true} if output format compare to one of avaliable types, {false} if not compare + */ + private static function validOutputFormatType( string $string ): bool { + return in_array( strtolower( $string ), array_map( 'strtolower', self::OUTPUT_FORMAT_TYPES ), true ); + } /** * - Add tracking categories @@ -186,10 +202,10 @@ class ParserKrokiTag { $output_format = $args['output_format'] ?? 'svg'; - //TODO: add check for format onlt png or svg - - //DEBUG - echo $output_format; + // Check for format only png or svg + if ( !self::validOutputFormatType( $output_format ) ) { + return $this->formatError( wfMessage( 'kroki-error-unknown-language' ) ); + } // set post fields $requestParams = [ @@ -247,10 +263,10 @@ class ParserKrokiTag { $output_format = $args['output_format'] ?? 'svg'; - //TODO: add check for format onlt png or svg - - //DEBUG - echo $output_format; + // Check for format only png or svg + if ( !self::validOutputFormatType( $output_format ) ) { + return $this->formatError( wfMessage( 'kroki-error-unknown-language' ) ); + } // set post fields $requestParams = [