Skip to content

Commit 9f13a29

Browse files
committed
fix: allow empty markdown uploads
1 parent efc2f4b commit 9f13a29

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

notify/main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,6 @@ func handleUpload(w http.ResponseWriter, r *http.Request, rootDir, authToken str
479479
http.Error(w, "failed to read upload body", http.StatusBadRequest)
480480
return
481481
}
482-
if len(data) == 0 {
483-
http.Error(w, "empty uploads are not allowed", http.StatusBadRequest)
484-
return
485-
}
486482

487483
if err := os.WriteFile(targetPath, data, 0o644); err != nil {
488484
http.Error(w, "failed to persist upload", http.StatusInternalServerError)

notify/main_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,27 @@ func TestHandleUploadStoresMarkdownUnderRoot(t *testing.T) {
310310
}
311311
}
312312

313+
func TestHandleUploadAcceptsEmptyMarkdown(t *testing.T) {
314+
root := t.TempDir()
315+
req := httptest.NewRequest(http.MethodPut, "/api/v1/upload?path=brain/notes/empty.md", strings.NewReader(""))
316+
req.Header.Set("Authorization", "Bearer token-123")
317+
rec := httptest.NewRecorder()
318+
319+
handleUpload(rec, req, root, "token-123")
320+
321+
if rec.Code != http.StatusOK {
322+
t.Fatalf("status = %d, want 200 (%s)", rec.Code, rec.Body.String())
323+
}
324+
325+
content, err := os.ReadFile(filepath.Join(root, "brain", "notes", "empty.md"))
326+
if err != nil {
327+
t.Fatalf("read uploaded file: %v", err)
328+
}
329+
if len(content) != 0 {
330+
t.Fatalf("stored content length = %d, want 0", len(content))
331+
}
332+
}
333+
313334
func TestHandleUploadRejectsPathTraversal(t *testing.T) {
314335
root := t.TempDir()
315336
req := httptest.NewRequest(http.MethodPut, "/api/v1/upload?path=../../evil.md", strings.NewReader("bad"))

0 commit comments

Comments
 (0)