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)
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 ==
// 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 = '_';
*/
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;
/**