Narigo / keepass-diff

A CLI-tool to diff Keepass (.kdbx) files. Useful, if syncing with Dropbox or NextCloud and getting multiple files due to conflicts.
https://keepass-diff.narigo.dev/
MIT License
306 stars 28 forks source link

Ignore line ending characters for diffing #56

Open FichteFoll opened 1 year ago

FichteFoll commented 1 year ago

Editing the file on a different platform (using a different tool) changes all line endings to the platform-specific ones. This can be observed with the following 3 files:

  1. File I created with a couple notes (single- and multi-line or no notes) on Linux using keepassxc 2.7.4.
  2. I had someone else edit file 1 on Windows using KeePass 2.53.1 (changed 2 user names).
  3. I edited file 2 again on Linux to change one username.

whitespacetest.zip

Diffing on CLI: 2023-04-18_14-12-42

Piping the diffs to a text editor that can render control chars (like CR), e.g. Sublime Text: 2023-04-18_14-16-36

$ keepass-diff --passwords whitespacetest --verbose whitespacetest_2_windows.kdbx whitespacetest_3_linux.kdbx | subl -n -

Initially raised at https://github.com/keepassxreboot/keepassxc/issues/9326 but it seems more relevant for the diff tool.

Narigo commented 1 year ago

Thank you for the issue and the test files! I haven't seen the notes field in my diffs with these control characters and didn't really think about multiline fields much when implementing this tool. Would it make sense to add an option like --ignore-line-endings then to ignore these control characters?

I think showing these characters is something that is not really in scope of this tool - it could be done on the Terminal level or as we have seen when pasting this into an editor.

I am thinking that the tool you're using to save your database shouldn't change the line endings though. It feels very odd to me that it changes all the different entries when nothing really changed in the file. Does it change them when you haven't changed anything at all? Like just pressing "Save" after opening it, would the file itself change?

FichteFoll commented 1 year ago

Does it change them when you haven't changed anything at all? Like just pressing "Save" after opening it, would the file itself change?

It does when selecting "Save Database as…" and doesn't allow me to save without having made any changes (keepassxc).

FichteFoll commented 1 year ago

Would it make sense to add an option like --ignore-line-endingsthen to ignore these control characters?

Definitely, though I'd argue it makes more sense to enable this by default and provide an option to disable it. Since keepass databases are a binary format and encrypted, it's not like you're likely to care which line endings are using inside of the note exactly as long as the tools you're opening them with handle them appropriately (which they mostly do). I presume this is also why keepassxc isn't all that interested in changing this behavior because outside of keepass-diff, I can't really think of any relevant use case where the type of line ending would matter.

lesensei commented 6 months ago

I'm in the same boat (using different keepass software on different devices with line breaks going a bit crazy), and I definitely would love that option (and even better if it's on by default) !