Repository navigation
Conversation
| } | ||
|
|
||
| func formatTableCell(column, value string) string { | ||
| value = Sanitize(value) |
There was a problem hiding this comment.
@samuel-jw Sanitize keeps \t \n \v \f \r everywhere, table cells included. \r in a table cell is still a display-spoofing vector: a token name like "USDC\rFAKE…" sends the cursor back to column 0 and the following text overwrites the address column, which is the case this function is meant to stop.
Keeping CR/LF makes sense for scalar output (e.g. contract source), but table cells should also replace \r, \v and \f (and probably \n, since tablewriter splits on it). Could you take a look?
There was a problem hiding this comment.
feedback updated
There was a problem hiding this comment.
@samuel-jw thanks, collapseWhitespace covers most of it, but a cell that is only whitespace still gets through. formatTableCell returns early before the collapse runs:
value = Sanitize(value)
trimmed := strings.TrimSpace(value)
if trimmed == "" {
return value // still holds the raw "\r"
}Repro: [{"to":"0xabc","tokenName":"\r","tokenSymbol":"USDC"}] renders as "0xabc \r USDC", so the next column overwrites the address again. The TUI goes through the same writeTable path.
Fix: return trimmed (or "") in that branch, and add a whitespace-only case like "\r" to TestTableCollapsesCursorControls.
|
@samuel-jw one note on the PR overall: the title says "ENS endpoint + some fixes" and the description is empty, but it bundles five independent changes:
The ENS part is ~10 lines; the rest is ~790. Could you split these into separate PRs, or at least add a description listing each change and why? It would make review and |
|
okay will add a more detail description, will separate them out as different PR in the future enh |
|
latest feedback updated, with a slightly different approach that also covers "\r" at the start or end of a cell (e.g. "\rUSDC"), which returning trimmed alone would miss. updated title and description as well |
Adds the
ens forwardresolvecommand and bundles five independent fixes found while working on it. Each section below says what changed, why, and which tests cover it. Most of the changes live in separate files (config/,tui/,output/), so each one can be reviewed or reverted on its own.ens forwardresolvecommandcli/registry.go,README.md--allkeeps raw JSON types and honours--compactcli/root.gooutput/output.goconfig/config.gooutput/output.go,cmd/etherscan/main.go,tui/tui.gotui/tui.go1.
ens forwardresolveetherscan ens forwardresolve <name>resolves an ENS name to its address. The command is markedMainnetOnly, because the API serves ENS on Ethereum mainnet only.enscommand group, the TUI sidebar entry and a README row.TestEnsForwardResolve2.
--allkeeps raw JSON types and honours--compactrunAllPagesturned every page into display rows (map[string]string) before combining them. As a result,--all -o jsonprinted numbers, booleans and nulls as strings, and arrays such asgetLogstopicsas JSON-encoded strings. A single-page call printed them correctly.--allalso ignored--compact.json.RawMessageuntiloutput.Write, which converts them only for table and CSV output.--compactis passed through.--allJSON output, non-string fields change type, so scripts that parsed the stringified form need updating.TestAllPagesPreservesJSONTypes3. Pretty JSON keeps numbers exact
output.Writedecoded intofloat64, which rounded integers above 2^53 and rewrote decimals such as1.50as1.5.UseNumber, so every number prints exactly as the API sent it.--compactwas never affected.TestWriteJSONKeepsExactNumbers4. Config save: atomic, 0600, symlink-aware
0600mode onos.OpenFileonly applies when the file is created, so an existing world-readable config stayed world-readable.O_TRUNCmeant a failed write left a truncated or empty config.Savewrites to a temp file in the same directory, then sets it to0600, syncs it to disk and renames it into place. A failed save leaves the old config intact.TestSaveTightensExistingPermissionsTestFailedSaveCleansUpTempFileTestSaveWritesThroughSymlinkTestSaveWritesThroughDanglingSymlinkTestSaveWritesThroughDanglingRelativeSymlinkTestSaveResolvesRelativeLinksPhysicallyTestSaveRoundTrips5. Terminal-escape sanitising (
output.Sanitize)\rcan return the cursor to column 0 and overwrite the address column in a table.Sanitizereplaces control characters and invalid UTF-8 with U+FFFD in every text output: table, CSV, single values, and error messages in both the CLI and the TUI.TestTextOutputStripsTerminalEscapesTestJSONOutputKeepsEscapedControlsTestTableCollapsesCursorControlsTestSanitizeKeepsWhitespaceAndTextTestCSVKeepsCRLFSource6. Windows: emoji input in the TUI
joinSurrogatesrecombines the two halves before key handling. This mirrors the fix in Bubble Tea v2, so it can be removed when we migrate.TestFormJoinsWindowsSurrogatePairs,TestChainPickerFilterJoinsWindowsSurrogatePairsRelease notes
etherscan ens forwardresolve <name>(Ethereum mainnet).--allJSON output keeps native JSON types instead of stringifying them, and--allnow honours--compact.0600, and preserves symlinked configs.Testing
go vet ./...andgo test ./...pass.