diff options
author | Sheogorath | 2018-07-27 13:44:45 +0200 |
---|---|---|
committer | Sheogorath | 2018-07-27 13:59:55 +0200 |
commit | 1f85017625bfd414f3b1a0d94ecbc37dc70d712a (patch) | |
tree | 9d69c3649a7f4b40810285424a47919dd65582e2 /lib | |
parent | 23bd1a18bb65dc49c55f755b02c9083ecdff1344 (diff) |
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 <sheogorath@shivering-isles.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/history.js | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/history.js b/lib/history.js index c7d2472c..63be4521 100644 --- a/lib/history.js +++ b/lib/history.js @@ -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)) { |