Skip to content

fix: remove trailing carriage return from --version output for cross-platform compatibility #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shackdown
Copy link

@shackdown shackdown commented Jun 26, 2025

What this PR does?

This PR updates the edit --version output to use platform-specific line endings:

  • On Windows: \r\n (carriage return + newline)
  • On Unix-like systems (Linux, macOS): \n only

Previously, the output always used \r\n, which introduced a trailing carriage return (\r) on Unix platforms. This caused subtle issues in shell scripts, such as incorrect string length and version comparison failures.

Before the fix:

ABC=$(./edit --version) ; echo ${#ABC}
# 19 (includes trailing \r)

After the fix:

ABC=$(./edit --version) ; echo ${#ABC}
# 18 (correct length)

closes: #527

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

That's not what's going on here and not the right way to fix this. CRLF line endings are needed on UNIX too, if ONLCR is not set. This is the case when we switch into raw mode. The switch occurs before we print the version message.

So, what we need to do is delay the raw mode switch until after we parsed all arguments, etc., and before we do anything else. Then we can print the version message with LF only on both Windows and UNIX.

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.

edit --version leaves trailing space
2 participants