Skip to content

Commit bbffdaa

Browse files
fix(favorite): avoid 500 when unfavoriting a note with no tags left (#554)
removeFromFavorites() can leave a note with no tags, in which case getTagsForObjects([$id]) returns an array without the $id key. Reading $tags[$id] then yields null, and in_array() throws a TypeError, so the PUT .../favorite request returns HTTP 500 even though the state change was already persisted. Guard the lookup with array_key_exists(), matching the defensive pattern already used in getAll() and getTags(). Fixes #553 Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c393cca commit bbffdaa

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
instead of a blank white area.
88

99
### Fixed
10+
- Unfavoriting a note no longer returns HTTP 500. When a note had no tags left
11+
after removing the favorite, `getTagsForObjects()` returns no entry for the
12+
note id, so `in_array()` was called with `null` and threw a `TypeError`. Guard
13+
the lookup with `array_key_exists()`, matching the pattern already used
14+
elsewhere in `NotesService`.
1015
- Restore the empty AngularJS hash prefix so clicking a note in the sidebar
1116
opens it again. The AngularJS 1.8 upgrade changed the default hash prefix to
1217
`!`, which broke the `#/notes/{id}` sidebar links so only the first note (or

service/notesservice.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ public function favorite($id, $favorite, $userId) {
181181
}
182182

183183
$tags = $tagger->getTagsForObjects([$id]);
184-
return \in_array(\OC\Tags::TAG_FAVORITE, $tags[$id]);
184+
$noteTags = \array_key_exists($id, $tags) ? $tags[$id] : [];
185+
return \in_array(\OC\Tags::TAG_FAVORITE, $noteTags);
185186
}
186187

187188
/**

0 commit comments

Comments
 (0)