diff --git a/kitty/dnd.c b/kitty/dnd.c index 415b905a9..4f254b3c4 100644 --- a/kitty/dnd.c +++ b/kitty/dnd.c @@ -693,7 +693,7 @@ drop_alloc_dir_handle(Window *w, const char *path, char **entries, size_t num_en w->drop.next_dir_handle_id++; /* Handles 0 and 1 are reserved (0 = absent, 1 = symlink indicator), so * valid directory handles must be >= 2. */ - if (w->drop.next_dir_handle_id <= 1) w->drop.next_dir_handle_id = 2; + if (w->drop.next_dir_handle_id < 2) w->drop.next_dir_handle_id = 2; DirHandle *h = &w->drop.dir_handles[w->drop.num_dir_handles++]; zero_at_ptr(h); h->id = w->drop.next_dir_handle_id; diff --git a/kitty_tests/dnd.py b/kitty_tests/dnd.py index 793abafed..ae1a72daf 100644 --- a/kitty_tests/dnd.py +++ b/kitty_tests/dnd.py @@ -753,7 +753,7 @@ class TestDnDProtocol(BaseTest): self.ae(events[0]['payload'].strip(), b'EINVAL') def test_uri_directory_transfer_tree(self) -> None: - """Full directory tree (≥ 3 levels deep) transfer: listing, sub-dirs, file integrity. + """Full directory tree (>= 3 levels deep) transfer: listing, sub-dirs, file integrity. Also verifies that every response from the terminal unambiguously identifies the filesystem object it refers to. For sub-directory @@ -2014,6 +2014,9 @@ class TestDnDProtocol(BaseTest): self.ae(ev['meta'].get('y'), '1') handle = dir_handle(ev) self.assertGreater(handle, 1, 'X= must be a directory handle (> 1)') + # In a fresh window the handle counter starts at 1, so the + # first allocated handle must be exactly 2. + self.ae(handle, 2, 'first allocated directory handle must be 2') self.assertIsNone(ev['meta'].get('Y'), 'Y= must not be present in top-level dir response')