File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,14 +31,27 @@ function getHistory (userid, callback) {
3131 history = JSON . parse ( user . history )
3232 // migrate LZString encoded note id to base64url encoded note id
3333 for ( let i = 0 , l = history . length ; i < l ; i ++ ) {
34+ // Calculate minimal string length for an UUID that is encoded
35+ // base64 encoded and optimize comparsion by using -1
36+ // this should make a lot of LZ-String parsing errors obsolete
37+ // as we can assume that a nodeId that is 48 chars or longer is a
38+ // noteID.
39+ const base64UuidLength = ( ( 4 * 36 ) / 3 ) - 1
40+ if ( ! ( history [ i ] . id . length > base64UuidLength ) ) {
41+ continue
42+ }
3443 try {
3544 let id = LZString . decompressFromBase64 ( history [ i ] . id )
3645 if ( id && models . Note . checkNoteIdValid ( id ) ) {
3746 history [ i ] . id = models . Note . encodeNoteId ( id )
3847 }
3948 } catch ( err ) {
4049 // most error here comes from LZString, ignore
41- logger . error ( err )
50+ if ( err . message === 'Cannot read property \'charAt\' of undefined' ) {
51+ logger . warning ( 'Looks like we can not decode "' + history [ i ] . id + '" with LZString. Can be ignored.' )
52+ } else {
53+ logger . error ( err )
54+ }
4255 }
4356 }
4457 history = parseHistoryToObject ( history )
Original file line number Diff line number Diff line change @@ -227,7 +227,11 @@ module.exports = function (sequelize, DataTypes) {
227227 var id = LZString . decompressFromBase64 ( noteId )
228228 if ( id && Note . checkNoteIdValid ( id ) ) { return callback ( null , id ) } else { return _callback ( null , null ) }
229229 } catch ( err ) {
230- logger . error ( err )
230+ if ( err . message === 'Cannot read property \'charAt\' of undefined' ) {
231+ logger . warning ( 'Looks like we can not decode "' + noteId + '" with LZString. Can be ignored.' )
232+ } else {
233+ logger . error ( err )
234+ }
231235 return _callback ( null , null )
232236 }
233237 } ,
You can’t perform that action at this time.
0 commit comments