From 8476ec3cb872c9ef6142c31004a0dff109dcc690 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 27 Sep 2018 17:04:48 +0100 Subject: [PATCH] exception: Avoid preg_replace for literal swap Follows-up bbcbcaba3db9. Change-Id: Ie7b76c28ba53668d73a8435c4d2ec91757bd2372 --- includes/exception/MWException.php | 4 +++- includes/exception/MWExceptionRenderer.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index 652a87dcfc..ffeafff50e 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -87,7 +87,9 @@ class MWException extends Exception { $res = wfMsgReplaceArgs( $fallback, $args ); // If an exception happens inside message rendering, // {{SITENAME}} sometimes won't be replaced. - $res = preg_replace( '/\{\{SITENAME\}\}/', $wgSitename, $res ); + $res = strtr( $res, [ + '{{SITENAME}}' => $wgSitename, + ] ); } return $res; } diff --git a/includes/exception/MWExceptionRenderer.php b/includes/exception/MWExceptionRenderer.php index 1f1cabeae1..503638303f 100644 --- a/includes/exception/MWExceptionRenderer.php +++ b/includes/exception/MWExceptionRenderer.php @@ -205,7 +205,9 @@ class MWExceptionRenderer { $res = wfMsgReplaceArgs( $fallback, $args ); // If an exception happens inside message rendering, // {{SITENAME}} sometimes won't be replaced. - $res = preg_replace( '/\{\{SITENAME\}\}/', $wgSitename, $res ); + $res = strtr( $res, [ + '{{SITENAME}}' => $wgSitename, + ] ); } return $res; } -- 2.20.1