From: Roan Kattouw Date: Tue, 9 Oct 2018 20:43:56 +0000 (-0700) Subject: resourceloader: Throw exception when config serialization fails X-Git-Tag: 1.34.0-rc.0~3799^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=abd3c02d08113027214fca69b8b776d2b2cd81ec;p=lhc%2Fweb%2Fwiklou.git resourceloader: Throw exception when config serialization fails If something puts a string that's invalid UTF-8 in a JS config variable, JSON serialization will fail on the entire config blob. Currently, this causes the entire config blob to be silently dropped, which breaks all JavaScript because elementary variables like wgPageName are missing. This change makes this scenario fail loudly rather than quietly, by throwing an exception. This also makes bugs like these easier to track down. Bug: T206475 Change-Id: Ief2ae00228389a23627d440dc1cd9a54cf2b6926 --- diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index fe9ba74a4f..e2b60fc672 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -1524,13 +1524,21 @@ MESSAGE; * * @param array $configuration List of configuration values keyed by variable name * @return string JavaScript code + * @throws Exception */ public static function makeConfigSetScript( array $configuration ) { - return Xml::encodeJsCall( + $js = Xml::encodeJsCall( 'mw.config.set', [ $configuration ], self::inDebugMode() ); + if ( $js === false ) { + throw new Exception( + 'JSON serialization of config data failed. ' . + 'This usually means the config data is not valid UTF-8.' + ); + } + return $js; } /**