From: Edward Chernenko Date: Mon, 18 Jun 2018 22:53:52 +0000 (+0300) Subject: Fix PHP warnings "preg_replace(): [...] invalid range in character class" X-Git-Tag: 1.31.2~86 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=f80e50f318a350c4486d272b1bc1bb5c22715a7c 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 (cherry picked from commit d88e924b6e5a7d529c471980e14f72430a94e546) --- diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index 81854abf03..9308a92d21 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -13,6 +13,7 @@ THIS IS NOT A RELEASE YET of "break". * (T206979) Fix PHP 7.3 warnings of using "compact()" when some variables may not be set. +* Fix PHP 7.3 warnings "preg_replace(): [...] invalid range in character class" == MediaWiki 1.31.1 == diff --git a/includes/media/FormatMetadata.php b/includes/media/FormatMetadata.php index 3ea71a927c..6cb33ac480 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; /**