Skip to content

Commit 735b806

Browse files
committed
Add check for noteId length
As we know the length of an UUID we can check if the base64 string of the provided UUID is long enough for a legacy base64 encoded nodeId and stop processing it in legacy mode, if it's not the case. This should make the ugly warning way less common. Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
1 parent bdb8631 commit 735b806

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/models/note.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ module.exports = function (sequelize, DataTypes) {
211211
},
212212
// parse note id by LZString is deprecated, here for compability
213213
parseNoteIdByLZString: function (_callback) {
214+
// Calculate minimal string length for an UUID that is encoded
215+
// base64 encoded and optimize comparsion by using -1
216+
// this should make a lot of LZ-String parsing errors obsolete
217+
// as we can assume that a nodeId that is 48 chars or longer is a
218+
// noteID.
219+
const base64UuidLength = ((4 * 36) / 3) - 1
220+
if (!(noteId.length > base64UuidLength)) {
221+
return _callback(null, null)
222+
}
214223
// try to parse note id by LZString Base64
215224
try {
216225
var id = LZString.decompressFromBase64(noteId)

0 commit comments

Comments
 (0)