preg_match and preg_match_all both do not set $matches on regex fail, leaving as it was set prior to call
Ouverte
Personne n'a encore pris cette issue.
Extension: pcre
Feature
Status: Verified
- Langage dominant
- C
- Étoiles
- 40.4k
- Forks
- 8.2k
- Merge moyen
- 2 j 13 h
- PR mergées (30 j)
- 96
Description
Description
The following code:
<?php // preg_match_all.php
$matches = [0 => 'Orange',
1 => 'Apple',
2 => 'Banana',
3 => 'Monkey'];
$result = preg_match_all('aeiou{0,', 'ou', $matches);
var_dump($result);
var_dump($matches);
$result = preg_match('aeiou{0,', 'ou', $matches);
var_dump($result);
var_dump($matches);
Resulted in this output from command line %php preg_match_all.php:
PHP Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 6
PHP Stack trace:
PHP 1. {main}() preg_match_all.php:0
PHP 2. preg_match_all($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:6
preg_match_all.php:7:
bool(false)
preg_match_all.php:8:
array(4) {
[0] =>
string(6) "Orange"
[1] =>
string(5) "Apple"
[2] =>
string(6) "Banana"
[3] =>
string(6) "Monkey"
}
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 10
PHP Stack trace:
PHP 1. {main}() preg_match_all.php:0
PHP 2. preg_match($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:10
preg_match_all.php:11:
bool(false)
preg_match_all.php:12:
array(4) {
[0] =>
string(6) "Orange"
[1] =>
string(5) "Apple"
[2] =>
string(6) "Banana"
[3] =>
string(6) "Monkey"
}
But I expected this output instead:
PHP Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 6
PHP Stack trace:
PHP 1. {main}() preg_match_all.php:0
PHP 2. preg_match_all($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:6
preg_match_all.php:7:
bool(false)
preg_match_all.php:8:
either: null or array[0]
PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 10
PHP Stack trace:
PHP 1. {main}() preg_match_all.php:0
PHP 2. preg_match($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:10
preg_match_all.php:11:
bool(false)
preg_match_all.php:12:
either: null or array[0]
PHP Version
PHP 7.4.27
Operating System
No response
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Reproduisez les appels fournis à preg_match() et preg_match_all() avec le motif invalide sur PHP 7.4.27, puis suivez les deux APIs dans l’interpréteur PHP. La tâche est terminée lorsqu’une correspondance échouée ne laisse plus inchangé le contenu précédent de $matches de l’appelant, avec une couverture de régression pour les deux fonctions.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- php
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100