Skip to content

Commit 1f85017

Browse files
committed
Minimize number of errors in LZString parsing errors for history
Right now we still see a lot of LZString parsing errors in the logs. They probably come from the user history. We should minimize the number by add the basic length check there as well. Signed-off-by: Sheogorath <[email protected]>
1 parent 23bd1a1 commit 1f85017

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/history.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ 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)) {

0 commit comments

Comments
 (0)