mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-27 20:36:29 -04:00
Fix slice bounds errors when editing notes on short entries
This commit is contained in:
+6
-3
@@ -30,9 +30,7 @@ func EditEntry(targetLocation string, hidePassword bool, field int) {
|
||||
unencryptedEntry := offline.DecryptGPG(targetLocation)
|
||||
|
||||
// ensure slice is long enough for field
|
||||
for len(unencryptedEntry) <= field {
|
||||
unencryptedEntry = append(unencryptedEntry, "")
|
||||
}
|
||||
unencryptedEntry = offline.EnsureSliceLength(unencryptedEntry, field)
|
||||
|
||||
// edit the field
|
||||
switch field {
|
||||
@@ -48,6 +46,7 @@ func EditEntry(targetLocation string, hidePassword bool, field int) {
|
||||
writeEntryShortcut(targetLocation, unencryptedEntry, hidePassword)
|
||||
}
|
||||
|
||||
// EditEntryNote edits the note of an entry at targetLocation (user input)
|
||||
func EditEntryNote(targetLocation string, hidePassword bool) {
|
||||
// ensure targetLocation exists
|
||||
offline.TargetIsFile(targetLocation, true, 2)
|
||||
@@ -55,6 +54,10 @@ func EditEntryNote(targetLocation string, hidePassword bool) {
|
||||
// read old entry data
|
||||
unencryptedEntry := offline.DecryptGPG(targetLocation)
|
||||
|
||||
// ensure slice is long enough for note
|
||||
// avoids errors when storing non-note data
|
||||
unencryptedEntry = offline.EnsureSliceLength(unencryptedEntry, 2) // 2 is used because it is the index of URL, the last non-note field
|
||||
|
||||
// store non-note data separately
|
||||
nonNoteData := unencryptedEntry[:3]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user