php / php/php-src

preg_match and preg_match_all both do not set $matches on regex fail, leaving as it was set prior to call

オープン
#7,917 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Extension: pcre Feature Status: Verified
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された preg_match() と preg_match_all() の呼び出しを、無効なパターンを使って PHP 7.4.27 で再現し、その後 PHP インタープリター内で 2 つの API を追跡します。完了条件は、マッチに失敗した場合に呼び出し元の以前の $matches の内容がそのまま残らなくなり、両方の関数に対するリグレッションテストのカバレッジがあることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。