Skip to content

Commit

Permalink
Minimize number of errors in LZString parsing errors for history
Browse files Browse the repository at this point in the 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]>
  • Loading branch information
SISheogorath committed Jul 27, 2018
1 parent 23bd1a1 commit 1f85017
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ function getHistory (userid, callback) {
history = JSON.parse(user.history)
// migrate LZString encoded note id to base64url encoded note id
for (let i = 0, l = history.length; i < l; i++) {
// Calculate minimal string length for an UUID that is encoded
// base64 encoded and optimize comparsion by using -1
// this should make a lot of LZ-String parsing errors obsolete
// as we can assume that a nodeId that is 48 chars or longer is a
// noteID.
const base64UuidLength = ((4 * 36) / 3) - 1
if (!(history[i].id.length > base64UuidLength)) {
continue
}
try {
let id = LZString.decompressFromBase64(history[i].id)
if (id && models.Note.checkNoteIdValid(id)) {
Expand Down

0 comments on commit 1f85017

Please sign in to comment.