Fix support for entries <4 lines long in EntryRefresh()

This commit is contained in:
2025-05-31 20:28:01 -04:00
parent c4db7dfd59
commit 346fa35dc8
+20 -10
View File
@@ -66,17 +66,27 @@ func EntryRefresh(oldRCWPassphrase, newRCWPassphrase []byte, removeOldDir bool)
return err return err
} }
// strip trailing whitespace... // strip trailing whitespace...
fieldsMain := decryptedEntry[:4] fieldsLength := len(decryptedEntry)
fieldsNote := back.RemoveTrailingEmptyStrings(decryptedEntry[4:]) if fieldsLength < 4 {
// ...from each non-note field fieldsMain := back.RemoveTrailingEmptyStrings(decryptedEntry)
for i, line := range fieldsMain { // ...from each non-note field
fieldsMain[i] = strings.TrimRight(line, " \t\r\n") for i, line := range fieldsMain {
} fieldsMain[i] = strings.TrimRight(line, " \t\r\n")
// ...and from each note line (preserve Markdown formatting) }
ClampTrailingWhitespace(fieldsNote) decryptedEntry = fieldsMain
} else {
fieldsMain := decryptedEntry[:4]
fieldsNote := back.RemoveTrailingEmptyStrings(decryptedEntry[4:])
// ...from each non-note field
for i, line := range fieldsMain {
fieldsMain[i] = strings.TrimRight(line, " \t\r\n")
}
// ...and from each note line (preserve Markdown formatting)
ClampTrailingWhitespace(fieldsNote)
// re-combine fields // re-combine fields
decryptedEntry = append(fieldsMain, fieldsNote...) decryptedEntry = append(fieldsMain, fieldsNote...)
}
// re-encrypt the entry with the new passphrase // re-encrypt the entry with the new passphrase
encBytes = wrappers.Encrypt([]byte(strings.Join(decryptedEntry, "\n")), newRCWPassphrase) encBytes = wrappers.Encrypt([]byte(strings.Join(decryptedEntry, "\n")), newRCWPassphrase)