Skip to content

Commit

Permalink
filter_var_array & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmisek committed Jul 22, 2024
1 parent 76f1614 commit 8fa7f4d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Peachpie.Runtime/Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public static byte[] ToBytes(this PhpValue value, Context ctx)
/// Checks the value is of type <c>string</c> or <c>&amp;string</c> and gets its value.
/// Single-byte strings are decoded using <c>UTF-8</c>.
/// </summary>
public static bool IsPhpArray(this PhpValue value, [MaybeNullWhen(false)]out PhpArray? array) => (array = value.AsArray()) != null;
public static bool IsPhpArray(this PhpValue value, [MaybeNullWhen(false)]out PhpArray array) => (array = value.AsArray()) != null;

/// <summary>
/// Checks the value is of type <c>string</c> or <c>&amp;string</c> and gets its value.
Expand Down Expand Up @@ -650,7 +650,7 @@ public static bool IsBinaryString(this PhpValue value, out PhpString @string)
/// <summary>
/// Gets value indicating the variable is Unicode string value.
/// </summary>
public static bool IsUnicodeString(this PhpValue value, /*[MaybeNullWhen(false)]*/out string? @string)
public static bool IsUnicodeString(this PhpValue value, [MaybeNullWhen(false)]out string @string)
{
switch (value.TypeCode)
{
Expand Down
35 changes: 35 additions & 0 deletions tests/web/filter_var_array.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace web\filter_var_array;

$data = array(
'product_id' => 'libgd<script>',
'component' => '10',
'versions' => '2.0.33',
'testscalar' => array('2', '23', '10', '12'),
'testarray' => '2',
);

$args = array(
'product_id' => FILTER_SANITIZE_ENCODED,
'component' => array('filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_FORCE_ARRAY,
'options' => array('min_range' => 1, 'max_range' => 10)
),
'versions' => FILTER_SANITIZE_ENCODED,
'doesnotexist' => FILTER_VALIDATE_INT,
'testscalar' => array(
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_SCALAR,
),
'testarray' => array(
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_FORCE_ARRAY,
)

);

$myinputs = filter_var_array($data, $args);

print_r($myinputs);

echo 'Done.';

0 comments on commit 8fa7f4d

Please sign in to comment.