From ecc66fcf9241c429cf2378f09793ecef3a00b098 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 20 Jun 2025 09:34:26 +0300 Subject: Fix line ending issue in dcat and add integration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed missing line endings in dcat output when not using --plain mode - Scanner.Bytes() strips newlines, so added logic to restore them - Only CatProcessor needs newlines added (GrepProcessor already adds them) - Added comprehensive integration tests for both dcat and dgrep line endings - Tests cover: basic usage, plain mode, multiple files, empty files, CRLF handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- internal/io/fs/directprocessor.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'internal/io/fs') diff --git a/internal/io/fs/directprocessor.go b/internal/io/fs/directprocessor.go index dd259b6..e02d4c2 100644 --- a/internal/io/fs/directprocessor.go +++ b/internal/io/fs/directprocessor.go @@ -114,9 +114,19 @@ func (dp *DirectProcessor) ProcessReader(ctx context.Context, reader io.Reader, return err } } else { + // Regular write path (e.g., stdout in serverless mode) if _, err := dp.output.Write(result); err != nil { return err } + + // Only add newline if the processor doesn't already handle it + // CatProcessor doesn't add newlines, but GrepProcessor does + if _, isCat := dp.processor.(*CatProcessor); isCat { + // Scanner strips newlines, so we need to add them back for cat + if _, err := dp.output.Write([]byte{'\n'}); err != nil { + return err + } + } } // Update transmission stats -- cgit v1.2.3