From 34185284fabc56eff6c1fe210442bb3d519f4f65 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Wed, 24 Jan 2024 10:56:26 +0300 Subject: [PATCH] fix: files from stdin only null separated (#615) --- cmd/run.go | 2 +- internal/lefthook/run.go | 4 ++-- testdata/files_override.txt | 9 --------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index bc73829e..9de6a8d7 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -60,7 +60,7 @@ func newRunCmd(opts *lefthook.Options) *cobra.Command { runCmd.Flags().BoolVar( &runArgs.FilesFromStdin, "files-from-stdin", false, - "get files from standard input, null- or \\n-separated", + "get files from standard input, null-separated", ) runCmd.Flags().StringSliceVar( diff --git a/internal/lefthook/run.go b/internal/lefthook/run.go index 42b45801..6e0db14c 100644 --- a/internal/lefthook/run.go +++ b/internal/lefthook/run.go @@ -294,12 +294,12 @@ func (l *Lefthook) configHookCommandCompletions(hookName string) []string { } } -// parseFilesFromString parses both `\0`- and `\n`-separated files. +// parseFilesFromString parses both `\0`-separated files. func parseFilesFromString(paths string) []string { var result []string start := 0 for i, c := range paths { - if c == 0 || c == '\n' { + if c == 0 { result = append(result, paths[start:i]) start = i + 1 } diff --git a/testdata/files_override.txt b/testdata/files_override.txt index d5032dcd..dc10b1f0 100644 --- a/testdata/files_override.txt +++ b/testdata/files_override.txt @@ -11,14 +11,6 @@ stdout 'a-file\.js b_file\.go c,file\.rb' exec lefthook run echo --file a-file.js --file ghost.file stdout 'a-file\.js ghost\.file' -stdin b_file.go -exec lefthook run echo --files-from-stdin -stdout 'b_file\.go c,file\.rb' - -stdin b_file.go -exec lefthook run echo --files-from-stdin --file ghost.file -stdout 'ghost\.file b_file\.go c,file\.rb' - -- lefthook.yml -- skip_output: - meta @@ -36,7 +28,6 @@ a-file.js -- b_file.go -- b_file.go -c,file.rb -- c,file.rb -- c,file.rb