Lucas_Werkmeister_WMDE created this task.
Lucas_Werkmeister_WMDE added projects: PHP 8.2 support, Wikidata, wdwb-tech.

TASK DESCRIPTION
  `utf8_encode()` and `utf8_decode()` are deprecated in PHP 8.2, because their 
names are quite misleading (RFC 
<https://wiki.php.net/rfc/remove_utf8_decode_and_utf8_encode>): they convert 
strings from Latin 1 to UTF-8 and vice versa.
  
  Wikibase uses them in `SimpleCacheWithBagOStuff` (since the original revision 
of that class):
  
        private function serialize( $value ) {
                $serializedValue = serialize( $value );
                $dataToStore = utf8_encode( $serializedValue );
    
                $signature = hash_hmac( 'sha256', $dataToStore, $this->secret );
                return json_encode( [ $signature, $dataToStore ] );
        }
    
        private function unserialize( $string, $default, array $loggingContext 
) {
                $result = json_decode( $string );
    
                // ...
                $decodedData = utf8_decode( $data );
    
                if ( $decodedData === serialize( false ) ) {
                        return false;
                }
    
                // phpcs:disable Generic.PHP.NoSilencedErrors.Discouraged
                $value = @unserialize(
                        $decodedData,
                        [
                                'allowed_classes' => [ \stdClass::class ]
                        ]
                );
    
                // ...
                return $value;
        }
  
  I’m pretty sure this use of the functions is pointless (though “correct” in 
that the methods perform their inverse operations). MediaWiki sets 
`mb_internal_encoding( 'UTF-8' );` early in `Setup.php` (since T137509 
<https://phabricator.wikimedia.org/T137509>), so there is no reason to assume 
that PHP `serialize()` returns Latin 1 that needs to be UTF-8 encoded before 
being passed into `json_encode()` – we’re just putting JSONified mojibake in 
the inner cache.
  
  name=shell.php
    > $c = new HashBagOStuff()
    > ( new Wikibase\Lib\SimpleCacheWithBagOStuff( $c, 'prefix', 'secret' ) 
)->set( 'key', 'äöü' )
    > $c->get( $c->makeKey( 'prefix', 'key' ) )
    = 
"["9b94f92e4cfdcd3a282fc9398acd9a77f6d74d72fe95930c67e3edc44ece2745","s:6:\"\u00c3\u00a4\u00c3\u00b6\u00c3\u00bc\";"]"
    > json_decode( $c->get( $c->makeKey( 'prefix', 'key' ) ) )[1] 
    = "s:6:"äöü";"
  
  We should remove both method calls. (But we’ll need to tweak the cache key at 
the same time, to ensure that old mojibake serializations don’t get 
deserialized without the `utf8_decode()`.)

TASK DETAIL
  https://phabricator.wikimedia.org/T324202

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Lucas_Werkmeister_WMDE
Cc: Umherirrender, Aklapper, Lucas_Werkmeister_WMDE, Astuthiodit_1, 
karapayneWMDE, Invadibot, maantietaja, ItamarWMDE, Akuckartz, Nandana, Lahi, 
Gq86, GoranSMilovanovic, TK-999, QZanden, LawExplorer, _jensen, rosalieper, 
Scott_WUaS, Wikidata-bugs, aude, Mbch331
_______________________________________________
Wikidata-bugs mailing list -- wikidata-bugs@lists.wikimedia.org
To unsubscribe send an email to wikidata-bugs-le...@lists.wikimedia.org

Reply via email to