File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -31,14 +31,27 @@ function getHistory (userid, callback) {
31
31
history = JSON . parse ( user . history )
32
32
// migrate LZString encoded note id to base64url encoded note id
33
33
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
+ }
34
43
try {
35
44
let id = LZString . decompressFromBase64 ( history [ i ] . id )
36
45
if ( id && models . Note . checkNoteIdValid ( id ) ) {
37
46
history [ i ] . id = models . Note . encodeNoteId ( id )
38
47
}
39
48
} catch ( err ) {
40
49
// 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
+ }
42
55
}
43
56
}
44
57
history = parseHistoryToObject ( history )
Original file line number Diff line number Diff line change @@ -227,7 +227,11 @@ module.exports = function (sequelize, DataTypes) {
227
227
var id = LZString . decompressFromBase64 ( noteId )
228
228
if ( id && Note . checkNoteIdValid ( id ) ) { return callback ( null , id ) } else { return _callback ( null , null ) }
229
229
} 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
+ }
231
235
return _callback ( null , null )
232
236
}
233
237
} ,
You can’t perform that action at this time.
0 commit comments