Skip to content

Commit 851f14a

Browse files
Improve regex grouping in filter_wp_unique_filename.
Move the literal dash outside the capture group so the regex reads `/(.*)-(\d+x\d+|scaled)-/` instead of alternating `(-\d+x\d+|-scaled)`. This keeps the dash handling consistent and simplifies the filename reconstruction. Props westonruter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d558ceb commit 851f14a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,8 +2167,8 @@ private static function filter_wp_unique_filename( $filename, $dir, $number, $at
21672167
}
21682168

21692169
$matches = array();
2170-
if ( preg_match( '/(.*)(-\d+x\d+|-scaled)-' . $number . '$/', $name, $matches ) ) {
2171-
$filename_without_suffix = $matches[1] . $matches[2] . ".$ext";
2170+
if ( preg_match( '/(.*)-(\d+x\d+|scaled)-' . $number . '$/', $name, $matches ) ) {
2171+
$filename_without_suffix = $matches[1] . '-' . $matches[2] . ".$ext";
21722172
if ( $matches[1] === $orig_name && ! file_exists( "$dir/$filename_without_suffix" ) ) {
21732173
return $filename_without_suffix;
21742174
}

0 commit comments

Comments
 (0)