Repository navigation
fix(cli): stop a body file with no content from wiping the page - #38
Merged
Merged
Conversation
A --body-file replaces: the new blocks are appended, then every old one is deleted. loadBody's empty check is the only thing standing between a file with no content and a body that is gone with nothing in its place, and it was strings.TrimSpace, which does not strip U+FEFF -- that left Unicode's White_Space in 6.3. So a BOM-only file -- what an editor on Windows writes for an empty file saved as UTF-8-with-BOM, and what `> notes.md` produces in PowerShell -- read as content. From there: goldmark returns zero blocks, ValidateAppendable ranges over an empty slice and returns nil, splitIntoRequests emits no batch so no PATCH goes out at all, and replaceBody deletes every non-sub-page child anyway. The wire trace is GET children, DELETE, and no write between them. Exit 0. PR #36 fixed the same bypass on the append path, where it costs a false appended:true. On the replace path it costs the body. isBlank already existed from that fix; this reuses it. The twin hole went with it: loadAppendBody re-checks emptiness after --expand, loadBody did not, so a file of nothing but "{{ticket}}" addressed by --page-id expanded to nothing, parsed to zero blocks, and took the same path. Both are argument handling in one command, though, and the content they protect is not recoverable. replaceBody now refuses a request with no blocks whatever the caller passed, so the property lives next to the deleting rather than two packages away from it. Also fixes the SKILL.md clause that PR #36's own change made stale: the over-limit message names a request size only when it built one, and a floor on the file size when it did not. Closes #37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🇬🇧 English
Summary
Closes #37.
--body-filereplaces: the new blocks are appended, then every old one is deleted.loadBody's empty check is the only thing between a file with no content and a body that is gone with nothing in its place — and it wasstrings.TrimSpace, which does not strip U+FEFF (it left Unicode'sWhite_Spacein 6.3).A BOM-only file therefore read as content. The chain from there, reproduced in a test:
goldmark returns zero blocks,
ValidateAppendableranges over an empty slice and returnsnil,splitIntoRequestsemits no batch so no PATCH goes out at all, andreplaceBodydeletes every non-sub-page child anyway. Exit 0.#36 fixed the same bypass on the append path, where it costs a false
appended:true. On the replace path it costs the body.isBlankalready existed from that fix; this reuses it.Two more things, same failure
--expand.loadAppendBodyre-checks emptiness after expanding;loadBodydid not. A file of nothing but{{ticket}}addressed by--page-idexpanded to nothing and took the same path.replaceBodynow refuses a request with no blocks, whatever the caller passed. Both guards above are argument handling inside one command, and the content they protect is not recoverable — so the property belongs next to the deleting, not two packages away from it.Also fixes the
SKILL.mdclause that #36 made stale: the over-limit message names a request size only when it built one, and a floor on the file size when it did not.Type of change
Checklist
go test ./... -racepassesgofmt,go vet,staticcheckare cleanREADME.mdandREADME.it.mdupdated if behavior changed (no user-facing README claim changed)🇮🇹 Italiano
Riepilogo
Chiude la #37.
--body-filesostituisce: scrive i blocchi nuovi e poi cancella tutti i vecchi. Il controllo sul vuoto inloadBodyè l'unica cosa fra un file senza contenuto e un corpo sparito senza nulla al suo posto — ed erastrings.TrimSpace, che non toglie U+FEFF (uscito daWhite_Spacein Unicode 6.3).Un file di solo BOM passava quindi per contenuto. La catena, riprodotta in un test: goldmark produce zero blocchi,
ValidateAppendableitera su una slice vuota e ritornanil,splitIntoRequestsnon emette batch quindi nessuna PATCH parte, ereplaceBodycancella comunque ogni figlio che non sia una sub-page. Exit 0.La #36 ha corretto lo stesso bypass sul path append, dove costa un
appended:truefalso. Sul path replace costa il corpo della pagina.isBlankesisteva già da quella fix: qui viene riusata.Altre due cose, stesso guasto
--expand.loadAppendBodyricontrolla il vuoto dopo l'espansione,loadBodyno. Un file di solo{{ticket}}indirizzato con--page-idsi espandeva a nulla e prendeva la stessa strada.replaceBodyora rifiuta una richiesta senza blocchi, qualunque cosa passi il chiamante. Le due guardie sopra vivono nella gestione degli argomenti di un solo comando, e il contenuto che proteggono non è recuperabile: la proprietà sta bene accanto al codice che cancella, non due package più in là.Corretta anche la subordinata di
SKILL.mdresa obsoleta dalla #36: il messaggio di superamento limite nomina la dimensione della richiesta solo quando l'ha costruita, e un pavimento sulla dimensione del file quando non l'ha fatto.