Skip to content

Fix Unexpected Newline in Output when Copying Empty Files #31

@supitsdu

Description

@supitsdu

During a code review of Pull Request #29, it was discovered that when ParseContent is used to copy content from an empty file, the output contains an unexpected newline character (\n) instead of an empty string. This behavior was observed in the following scenario:

  • The readers slice passed to ParseContent contains a FileContentReader where the FilePath points to an empty file.
  • The function returns a string containing only a newline character ("\n") instead of an empty string ("").

Expected Behavior:

When copying content from an empty file, ParseContent should return an empty string to accurately reflect the lack of content in the file.

Proposed Fix:

Add a check within the loop in ParseContent to ensure that the content read from each reader is not empty before appending a newline character and writing it to the strings.Builder.

Additional Notes:

  • Review the unit tests for ParseContent to ensure they cover the case of empty file input.
  • Consider adding a test specifically for this scenario to prevent regressions in the future.

Originally posted by @ccoVeille in #29 (comment)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working as expectedrefactoringIssues or PRs to improving code structure, without changing its external behaviortestingIssues or PRs specifically related to Go testing frameworks or practices.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions