Repository navigation
Conversation
graft show prints the author, the subject and the file paths of a commit as they are. These strings come from other clients: a commit whose subject carries a terminal escape sequence would move the cursor of the terminal of whoever reads it and overwrite the lines above, for example to forge which files a commit changed. Every other command already shows such text through displayText: search, review, conflicts, log and the repo commands do. show did not. Route the author, the subject and the paths of show through displayText too, and check the escaping with a regression test.
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.
Summary
graft show(text output) printed the commit's author, subject and file paths raw. These strings come from other clients: a commit whose subject or file name carries a terminal escape sequence would act on the terminal of whoever reads the output — move the cursor, erase lines above it, or forge which files a commit changed.Every other command already routes server-reported text through
displayText(search, review, conflicts, log, the repo commands — seedisplay_test.goandreview_escape_test.go).showdid not. This PR wraps the author, the subject and the file paths of the text branch ofshowindisplayText, and adds a regression test.The
--jsonoutput is unchanged (JSON encoding already escapes control characters), so consumers of the superfan format see no difference.Problem
A commit created by another client with, say, subject
fix\x1b[1A\x1b[2Kforgedand pathledger/a\x1b[2J.txtprints those bytes raw; the escape sequences erase thecommit/Authorlines above and can rewrite the file list on screen.searchandreview showalready guard against exactly this for the same reason.Verification
Ada\x1b[2K <ada@example.com>, subjectfix\x1b[1A\x1b[2Kforgedand pathledger/a\x1b[2J.txtleaves raw0x1bbytes in the output; the same rendering throughdisplayTextprintsAda\x1b[2K <ada@example.com>,fix\x1b[1A\x1b[2Kforgedandledger/a\x1b[2J.txtwith no raw escape left.TestCLIShowEscapesServerTextfails on the old code (raw\x1breaches the terminal) and passes with the fix, following the pattern ofTestCLIReviewShowEscapesServerText.TestShowJSONIsOneObjectOfTheSuperfanFormatandTestShowJSONListsAreNeverNullare unaffected: only the text branch changed.