Skip to content
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

patch.py adds extra newline at EOF #50

Open
nils-ballmann opened this issue Mar 29, 2017 · 1 comment
Open

patch.py adds extra newline at EOF #50

nils-ballmann opened this issue Mar 29, 2017 · 1 comment

Comments

@nils-ballmann
Copy link

I have observed that patch.py adds an extra newline at the end of the patched file even though the unified patch doesn't alter the line at all.

I know it is good behavior on Linux to have a newline at the end of the file. Some C/C++ coding standards make this even mandatory. But with PHP and some other web technologies, there are strong reasons to NOT have a newline at the end of the file, as it may result in undesired additional newline output to the client, possibly breaking everything.

Small example for illustration, including [LF] as newline ('\n') and [EOF] as the end of the file.

original file (old/test.php):

<?php[LF]
[LF]
echo "<html><title>asdf</title><body>asdf</body></html>";[LF]
[LF]
?>[EOF]

with patch file (without [LF] and [EOF], generated via diff -Naur old/test.php new/test.php > test.php.patch):

--- old/test.php	2017-03-29 11:19:36.103349100 +0200
+++ new/test.php	2017-03-29 11:20:16.270349100 +0200
@@ -1,5 +1,5 @@
 <?php
 
-echo "<html><title>asdf</title><body>asdf</body></html>";
+echo "<html><title>A real title</title><body>A real body</body></html>";
 
 ?>
\ No newline at end of file

becomes:

<?php[LF]
[LF]
echo "<html><title>A real title</title><body>A real body</body></html>";[LF]
[LF]
?>[LF][EOF]

but should be (new/test.php):

<?php[LF]
[LF]
echo "<html><title>A real title</title><body>A real body</body></html>";[LF]
[LF]
?>[EOF]
@nils-ballmann
Copy link
Author

nils-ballmann commented Mar 29, 2017

And this is in contrast to (cygwin) patch behavior:

BASH [user@host] ~/Desktop/test
$ cat test.php
<?php

echo "<html><title>asdf</title><body>asdf</body></html>";

?>BASH [user@host] ~/Desktop/test
$ patch -p1 < ./test.php.patch
patching file test.php
BASH [user@host] ~/Desktop/test
$ cat test.php
<?php

echo "<html><title>A real title</title><body>A real body</body></html>";

?>BASH [user@host] ~/Desktop/test

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

No branches or pull requests

1 participant