preg_match and preg_match_all both do not set $matches on regex fail, leaving as it was set prior to call
Đang mở
Chưa có ai nhận issue này.
Extension: pcre
Feature
Status: Verified
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.2k
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 96
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện các lệnh gọi preg_match() và preg_match_all() được cung cấp với mẫu không hợp lệ trên PHP 7.4.27, sau đó truy vết hai API trong trình thông dịch PHP. Hoàn tất có nghĩa là một lần khớp thất bại không còn giữ nguyên nội dung $matches trước đó của bên gọi, với độ bao phủ hồi quy cho cả hai hàm.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- php
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100