Skip to content

Test script outputs incorrect difference empty blank lines #13083

@jorgsowa

Description

@jorgsowa

Description

The script run-test.php calculates the wrong lines of difference for the given test.

--TEST--
Test preg_grep() function : error conditions - bad regular expressions
--FILE--
<?php
$values = [
    'abcdef', //Regex without delimiter
    '/[a-zA-Z]', //Regex without closing delimiter
    '[a-zA-Z]/', //Regex without opening delimiter
    '/[a-zA-Z]/F',
    [
        '[a-z]', //Array of Regexes
        '[A-Z]',
        '[0-9]',
    ],
    '/[a-zA-Z]/', //Regex string
];
$array = [123, 'abc', 'test'];
foreach ($values as $value) {
    try {
        var_dump(preg_grep($value, $array));
    } catch (TypeError $e) {
        echo $e->getMessage(), "\n";
    }
}
$value = new stdclass(); //Object
try {
    var_dump(preg_grep($value, $array));
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}
?>
--EXPECTF--

Warning: preg_grep(): Delimiter must not be alphanumeric, backslash, or NUL in %spreg_grep_error1.php on line %d
bool(false)


Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
bool(false)

Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d
bool(false)

Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d
bool(false)
preg_grep(): Argument #1 ($pattern) must be of type string, array given

array(2) {
  [1]=>
  string(3) "abc"
  [2]=>
  string(4) "test"
}
preg_grep(): Argument #1 ($pattern) must be of type string, stdClass given

Resulted in this output:

Warning: preg_grep(): Delimiter must not be alphanumeric, backslash, or NUL byte in %spreg_grep_error1.php on line %d
     bool(false)
     
004- 
005- Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
006- bool(false)
007- 
008- Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d
009- bool(false)
010- 
011- Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d
012- bool(false)
013- preg_grep(): Argument #1 ($pattern) must be of type string, array given
014- 
     Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
     bool(false)
     
--

But I expected this output instead:

Warning: preg_grep(): Delimiter must not be alphanumeric, backslash, or NUL byte in %spreg_grep_error1.php on line %d
     bool(false)
     
004- 
     Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
     bool(false)
     
--
     Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d
     bool(false)
     preg_grep(): Argument #1 ($pattern) must be of type string, array given
014-
     Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
     bool(false)
     
--

PHP Version

PHP 8.3

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions