Escape tab, newline, CR and backslash in report paths (closes #7)
check / check (push) Successful in 1m29s
check / check (push) Successful in 1m29s
A path holding a tab or newline split a row of the report or trees output. The path columns of both now write a backslash, tab, newline and carriage return as \\, \t, \n and \r; every other byte is written unchanged. Grouping and sorting still use the stored path. Warnings on stderr are escaped the same way in warnf, so each stays one line. In trees, the root directory's node now has the path "/" instead of an empty string, and its children's paths start with a single slash. README states the rule under "Report output format". Model: opus-5-5
This commit was merged in pull request #70.
This commit is contained in:
@@ -62,7 +62,8 @@ func runTrees(ctx context.Context) error {
|
||||
first := g[0]
|
||||
for _, n := range g[1:] {
|
||||
_, err = fmt.Fprintf(out, "%s\t%s\t%d\t%d\n",
|
||||
first.path, n.path, first.fileCount, first.totalSize)
|
||||
escapePath(first.path), escapePath(n.path),
|
||||
first.fileCount, first.totalSize)
|
||||
if err != nil {
|
||||
return fmt.Errorf("write stdout: %w", err)
|
||||
}
|
||||
@@ -87,8 +88,8 @@ func runTrees(ctx context.Context) error {
|
||||
|
||||
// buildHierarchy reconstructs the directory hierarchy from the record
|
||||
// paths under a synthetic super-root. Paths are split on "/"; for
|
||||
// absolute paths the first component is empty, which simply becomes a
|
||||
// top-level node representing "/". It returns the super-root and every
|
||||
// absolute paths the first component is empty, which becomes the
|
||||
// top-level node with path "/". It returns the super-root and every
|
||||
// directory node created.
|
||||
func buildHierarchy(recs []scanRec) (*treeNode, []*treeNode) {
|
||||
super := &treeNode{}
|
||||
@@ -102,9 +103,17 @@ func buildHierarchy(recs []scanRec) (*treeNode, []*treeNode) {
|
||||
for _, c := range comps[:len(comps)-1] {
|
||||
child := node.dirs[c]
|
||||
if child == nil {
|
||||
childPath := c
|
||||
if node != super {
|
||||
childPath = node.path + "/" + c
|
||||
childPath := node.path + "/" + c
|
||||
|
||||
// The root directory's path is "/", not empty, and its
|
||||
// children's paths start with one slash, not two.
|
||||
switch {
|
||||
case node == super && c == "":
|
||||
childPath = "/"
|
||||
case node == super:
|
||||
childPath = c
|
||||
case node.path == "/":
|
||||
childPath = "/" + c
|
||||
}
|
||||
|
||||
child = &treeNode{path: childPath, parent: node}
|
||||
|
||||
Reference in New Issue
Block a user