[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Weilin Du | Date: | Tue, 20 Oct 2026 17:38:55 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142507@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-10-21T01:36:01+08:00
Commit: https://github.com/php/php-src/commit/c20480380a99027a95ec4f71354267bd528cac12
Raw diff: https://github.com/php/php-src/commit/c20480380a99027a95ec4f71354267bd528cac12.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
Fix glob() not negating bracket expressions that start with "^" (#24422)
Changed paths:
A ext/standard/tests/file/glob_bracket_negation.phpt
M NEWS
M main/php_glob.c
Diff:
diff --git a/NEWS b/NEWS
index ed820a1d54f5..cd863b0443bd 100644
--- a/NEWS
+++ b/NEWS
@@ -114,6 +114,8 @@ PHP NEWS
(Nicolas Grekas)
. Fixed bug GH-24399 (usleep() and time_nanosleep() ignore queued APCs on
Windows). (Nicolas Grekas)
+ . Fixed glob() not negating bracket expressions that start with "^".
+ (Nicolas Grekas)
- Tidy:
. Fixed tidy_repair_string(), tidy_repair_file(), tidy::repairString() and
diff --git a/ext/standard/tests/file/glob_bracket_negation.phpt
b/ext/standard/tests/file/glob_bracket_negation.phpt
new file mode 100644
index 000000000000..3f5ef513789e
--- /dev/null
+++ b/ext/standard/tests/file/glob_bracket_negation.phpt
@@ -0,0 +1,30 @@
+--TEST--
+glob() negates a bracket expression that starts with "!" or "^"
+--FILE--
+<?php
+$dir = __DIR__ . '/glob_bracket_negation';
+@mkdir($dir);
+foreach (['a', 'b', 'c', '^', '!'] as $name) {
+ touch("$dir/$name");
+}
+
+foreach (['[!a]', '[^a]', '[!a-b]', '[^a-b]',
'[!]a]', '[^]a]', '[a^]'] as $pattern) {
+ echo $pattern, ': ', implode(' ', array_map('basename',
glob("$dir/$pattern"))), "\n";
+}
+?>
+--CLEAN--
+<?php
+$dir = __DIR__ . '/glob_bracket_negation';
+foreach (['a', 'b', 'c', '^', '!'] as $name) {
+ @unlink("$dir/$name");
+}
+@rmdir($dir);
+?>
+--EXPECT--
+[!a]: ! ^ b c
+[^a]: ! ^ b c
+[!a-b]: ! ^ c
+[^a-b]: ! ^ c
+[!]a]: ! ^ b c
+[^]a]: ! ^ b c
+[a^]: ^ a
diff --git a/main/php_glob.c b/main/php_glob.c
index 8edfb8326da4..af087c4530a6 100644
--- a/main/php_glob.c
+++ b/main/php_glob.c
@@ -107,6 +107,7 @@
#include "charclass.h"
+#define CIRCUMFLEX '^'
#define DOLLAR '$'
#define DOT '.'
#define EOS '\0'
@@ -566,6 +567,12 @@ static int glob0(const Char *pattern, php_glob_t *pglob, struct glob_lim
*limitp
switch (c) {
case LBRACKET:
c = *qpatnext;
+ /*
+ * Not in OpenBSD's glob(), keep it when syncing: like fnmatch(),
+ * treat a leading '^' as '!'.
+ */
+ if (c == CIRCUMFLEX)
+ c = NOT;
if (c == NOT)
++qpatnext;
if (*qpatnext == EOS ||