From 270238e060e8972ee473a5099e23fd28a8c6eadc Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Wed, 6 Sep 2023 13:25:07 +0545 Subject: [PATCH] [PHP] convert data to string before giving it to preg_match (#16513) --- .../src/main/resources/php/model_generic.mustache | 2 +- .../petstore/php/OpenAPIClient-php/lib/Model/FormatTest.php | 6 +++--- samples/client/petstore/php/psr-18/lib/Model/FormatTest.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/model_generic.mustache b/modules/openapi-generator/src/main/resources/php/model_generic.mustache index b4eb47f5fba..aa508136092 100644 --- a/modules/openapi-generator/src/main/resources/php/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/php/model_generic.mustache @@ -449,7 +449,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par } {{/minimum}} {{#pattern}} - if ({{#isNullable}}!is_null(${{name}}) && {{/isNullable}}(!preg_match("{{{pattern}}}", ${{name}}))) { + if ({{#isNullable}}!is_null(${{name}}) && {{/isNullable}}(!preg_match("{{{pattern}}}", ObjectSerializer::toString(${{name}})))) { throw new \InvalidArgumentException("invalid value for \${{name}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}."); } {{/pattern}} diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/FormatTest.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/FormatTest.php index 20407f558ac..526e4e14c73 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/FormatTest.php @@ -718,7 +718,7 @@ class FormatTest implements ModelInterface, ArrayAccess, \JsonSerializable throw new \InvalidArgumentException('non-nullable string cannot be null'); } - if ((!preg_match("/[a-z]/i", $string))) { + if ((!preg_match("/[a-z]/i", ObjectSerializer::toString($string)))) { throw new \InvalidArgumentException("invalid value for \$string when calling FormatTest., must conform to the pattern /[a-z]/i."); } @@ -919,7 +919,7 @@ class FormatTest implements ModelInterface, ArrayAccess, \JsonSerializable throw new \InvalidArgumentException('non-nullable pattern_with_digits cannot be null'); } - if ((!preg_match("/^\\d{10}$/", $pattern_with_digits))) { + if ((!preg_match("/^\\d{10}$/", ObjectSerializer::toString($pattern_with_digits)))) { throw new \InvalidArgumentException("invalid value for \$pattern_with_digits when calling FormatTest., must conform to the pattern /^\\d{10}$/."); } @@ -951,7 +951,7 @@ class FormatTest implements ModelInterface, ArrayAccess, \JsonSerializable throw new \InvalidArgumentException('non-nullable pattern_with_digits_and_delimiter cannot be null'); } - if ((!preg_match("/^image_\\d{1,3}$/i", $pattern_with_digits_and_delimiter))) { + if ((!preg_match("/^image_\\d{1,3}$/i", ObjectSerializer::toString($pattern_with_digits_and_delimiter)))) { throw new \InvalidArgumentException("invalid value for \$pattern_with_digits_and_delimiter when calling FormatTest., must conform to the pattern /^image_\\d{1,3}$/i."); } diff --git a/samples/client/petstore/php/psr-18/lib/Model/FormatTest.php b/samples/client/petstore/php/psr-18/lib/Model/FormatTest.php index 20407f558ac..526e4e14c73 100644 --- a/samples/client/petstore/php/psr-18/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/psr-18/lib/Model/FormatTest.php @@ -718,7 +718,7 @@ class FormatTest implements ModelInterface, ArrayAccess, \JsonSerializable throw new \InvalidArgumentException('non-nullable string cannot be null'); } - if ((!preg_match("/[a-z]/i", $string))) { + if ((!preg_match("/[a-z]/i", ObjectSerializer::toString($string)))) { throw new \InvalidArgumentException("invalid value for \$string when calling FormatTest., must conform to the pattern /[a-z]/i."); } @@ -919,7 +919,7 @@ class FormatTest implements ModelInterface, ArrayAccess, \JsonSerializable throw new \InvalidArgumentException('non-nullable pattern_with_digits cannot be null'); } - if ((!preg_match("/^\\d{10}$/", $pattern_with_digits))) { + if ((!preg_match("/^\\d{10}$/", ObjectSerializer::toString($pattern_with_digits)))) { throw new \InvalidArgumentException("invalid value for \$pattern_with_digits when calling FormatTest., must conform to the pattern /^\\d{10}$/."); } @@ -951,7 +951,7 @@ class FormatTest implements ModelInterface, ArrayAccess, \JsonSerializable throw new \InvalidArgumentException('non-nullable pattern_with_digits_and_delimiter cannot be null'); } - if ((!preg_match("/^image_\\d{1,3}$/i", $pattern_with_digits_and_delimiter))) { + if ((!preg_match("/^image_\\d{1,3}$/i", ObjectSerializer::toString($pattern_with_digits_and_delimiter)))) { throw new \InvalidArgumentException("invalid value for \$pattern_with_digits_and_delimiter when calling FormatTest., must conform to the pattern /^image_\\d{1,3}$/i."); }