From d88e924b6e5a7d529c471980e14f72430a94e546 Mon Sep 17 00:00:00 2001 From: Edward Chernenko Date: Tue, 19 Jun 2018 01:53:52 +0300 Subject: [PATCH] Fix PHP warnings "preg_replace(): [...] invalid range in character class" This was spotted when running tests on Travis (PHP 7.3 nighly, trusty). Two expressions inside preg_replace() contained non-escaped "-" inside [], where this "-" meant an actual "-" character. The warning is because "-" has special meaning inside [] ("a-z" for range), and things like [\w-.] are considered "invalid range". Solution is to escape "-" like this: [\w\-.] Change-Id: I41cc217081f00f54d957b6d8052ee209412f5ff6 --- includes/media/FormatMetadata.php | 4 ++-- includes/upload/UploadStash.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/media/FormatMetadata.php b/includes/media/FormatMetadata.php index 52d7373aab..9ebc63f678 100644 --- a/includes/media/FormatMetadata.php +++ b/includes/media/FormatMetadata.php @@ -1859,9 +1859,9 @@ class FormatMetadata extends ContextSource { // drop all characters which are not valid in an XML tag name // a bunch of non-ASCII letters would be valid but probably won't // be used so we take the easy way - $key = preg_replace( '/[^a-zA-z0-9_:.-]/', '', $key ); + $key = preg_replace( '/[^a-zA-z0-9_:.\-]/', '', $key ); // drop characters which are invalid at the first position - $key = preg_replace( '/^[\d-.]+/', '', $key ); + $key = preg_replace( '/^[\d\-.]+/', '', $key ); if ( $key == '' ) { $key = '_'; diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index e25b11ec23..e55ab1fbb7 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -52,7 +52,7 @@ */ class UploadStash { // Format of the key for files -- has to be suitable as a filename itself (e.g. ab12cd34ef.jpg) - const KEY_FORMAT_REGEX = '/^[\w-\.]+\.\w*$/'; + const KEY_FORMAT_REGEX = '/^[\w\-\.]+\.\w*$/'; const MAX_US_PROPS_SIZE = 65535; /** -- 2.20.1