Platform: Handle invalid JSON in the other path in #getUserConfig

I discovered recently that I had 64 KB of text stored in the
'visualeditor-findAndReplace-findText' preference.

I must have accidentally copy-pasted a whole page into the "Find"
field, the JSON that VisualEditor tried to save became invalid after
MySQL chopped off the string after 64 KB, and since then VisualEditor
was unable to update the find-and-replace dialog preferences.

Change-Id: Ib1d853263d873d969c7b015b3842524e1f7fc351
This commit is contained in:
Bartosz Dziewoński 2022-11-06 22:39:30 +01:00
parent 17b983a20b
commit 288159d65c

View file

@ -116,14 +116,19 @@ ve.init.mw.Platform.prototype.getUserConfig = function ( keys ) {
var values = mw.user.options.get( keys );
var parsedValues = {};
Object.keys( values ).forEach( function ( value ) {
parsedValues[ value ] = JSON.parse( values[ value ] );
try {
parsedValues[ value ] = JSON.parse( values[ value ] );
} catch ( e ) {
// We might encounter corrupted values in the store
parsedValues[ value ] = null;
}
} );
return parsedValues;
} else {
try {
return JSON.parse( mw.user.options.get( keys ) );
} catch ( e ) {
// We might encounter an old unencoded value in the store
// We might encounter corrupted values in the store
return null;
}
}