Skip to content

Add missing new lines#324

Merged
mattosaurus merged 4 commits intomasterfrom
bug/306-fix-newline-verification-error
Feb 23, 2026
Merged

Add missing new lines#324
mattosaurus merged 4 commits intomasterfrom
bug/306-fix-newline-verification-error

Conversation

@mattosaurus
Copy link
Owner

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR attempts to fix issue #306 where consecutive newlines in clear-signed PGP messages cause verification failures. The fix adds line separators to the output stream within the message processing loop, which were previously missing and causing empty lines to be lost.

Changes:

  • Added conditional line separator writes in the clear-sign verification loop to preserve consecutive newlines
  • Changed variable declarations from explicit types (int, byte[]) to implicit var for consistency

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
PgpCore/PGP.VerifySync.cs Added logic to write line separators in the clear-sign verification loop and changed variable types to var
PgpCore/PGP.VerifyAsync.cs Same changes as sync version to maintain consistency between sync and async implementations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

line = lineOut.ToArray();
await outStream.WriteAsync(line, 0, GetLengthWithoutSeparatorOrTrailingWhitespace(line));
// Add missing new line
if (lookAhead != 1)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition lookAhead != 1 is incorrect. The value 1 represents ASCII character 1 (SOH - Start of Heading), not the end of stream. Based on the ReadInputLine implementation and consistent usage throughout the codebase, lookAhead returns -1 when the end of stream is reached. This condition should be lookAhead != -1 to add a line separator for all lines except the last one.

Suggested change
if (lookAhead != 1)
if (lookAhead != -1)

Copilot uses AI. Check for mistakes.
line = lineOut.ToArray();
outStream.Write(line, 0, GetLengthWithoutSeparatorOrTrailingWhitespace(line));
// Add missing new line
if (lookAhead != 1)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix for issue #306 (handling consecutive newlines in clear-signed messages) lacks test coverage. Consider adding tests that verify messages containing consecutive newlines such as "foo\nbar\n\n" or "foo\n\nbar" are correctly signed and verified, as these were the failing cases reported in the issue.

Suggested change
if (lookAhead != 1)
if (lookAhead != -1)

Copilot uses AI. Check for mistakes.
line = lineOut.ToArray();
outStream.Write(line, 0, GetLengthWithoutSeparatorOrTrailingWhitespace(line));
// Add missing new line
if (lookAhead != 1)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition lookAhead != 1 is incorrect. The value 1 represents ASCII character 1 (SOH - Start of Heading), not the end of stream. Based on the ReadInputLine implementation and consistent usage throughout the codebase, lookAhead returns -1 when the end of stream is reached. This condition should be lookAhead != -1 to add a line separator for all lines except the last one.

Suggested change
if (lookAhead != 1)
if (lookAhead != -1)

Copilot uses AI. Check for mistakes.
@mattosaurus mattosaurus merged commit f24db44 into master Feb 23, 2026
@mattosaurus mattosaurus deleted the bug/306-fix-newline-verification-error branch February 23, 2026 19:38
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants