This concerns the implementation of the unserialize function of the BaseItem.
The issue:
If a saved/synchronized file contains newlines at the end of the file the file cannot be imported as a note.
The cause:
The unserialize method steps through the files split into lines in reverse and assumes it has reached the end of file metadata information once it reaches an empty line. If there is an empty line at the end of the file thus creating an empty object to be imported and rightly raising an error due to a missing type_
property.
This is not a problem as such, as it works fine as long as the user does not touch the saved/synchronized notes with an editor or other tools, which often times insert a newline at the end of text files. I only ran into this issue as I actively touched the synchronized files in an attempt to troubleshoot another issue (which was due to not having the latest version of the app).
I would be happy to improve the code so be more resilient to issues like this and maybe a bit simpler if you’d be interested. I didn’t really understand it the first time I had a look at it, due to a lot of string handling and conditions.
I could use some pointers:
- is there any sort of test setup to make sure I’m not breaking anything, when changing the code (didn’t find anything on the fly)?
- is there a particular reason, why the title and content of a note is at the top as cleartext only seperated by a newline and not just another property other than historical ones? I think the serialization and deserialization would be considerable simpler with a different format.
- any ideas/plans on file format transformation or versioning to support multiple app versions in the future if there are new fields introduced/required? This would enable features, like showing the user a message saying they need to upgrade to a new app version, without them having to go to the forums to report a bug and/or allowing automatic transformations to a new file “schema” version.
What are your thoughts on this?