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

Missing "No newline at end of file" when comparing two texts that do not end in newlines #94

Closed
federicotdn opened this issue Dec 29, 2015 · 3 comments

Comments

@federicotdn
Copy link

I created two text files, t1.txt:

line1
line2
line3

and t2.txt:

line1
line2
line33

Neither of them have a newline at the end.

Using the diff tool, I get:

$ ls
t1.txt  t2.txt
$ diff -u t1.txt t2.txt
--- t1.txt  2015-12-29 00:46:20.201829172 -0300
+++ t2.txt  2015-12-29 00:46:28.146828695 -0300
@@ -1,3 +1,3 @@
 line1
 line2
-line3
\ No newline at end of file
+line33
\ No newline at end of file

Using jsdiff, I get (on Node):

> var p = diff.createPatch("", "line1\nline2\nline3", "line1\nline2\nline33")
undefined
> console.log(p)
Index: 
===================================================================
--- 
+++ 
@@ -1,3 +1,3 @@
 line1
 line2
-line3
\ No newline at end of file
+line33

There's a \ No newline at end of file missing after +line33.

I think this only happens when the last line has changed, but both new and old versions don't end in a newline. I couldn't find a test case in https://github.com/kpdecker/jsdiff/blob/master/test/patch/create.js which covers this case.

Tested on 2.2.1.

@joonhyublee
Copy link

I'm having the same problem. I'll try to find the cause and give you an update.

@leemgs
Copy link

leemgs commented Mar 6, 2017

ubuntu$> vi source.cpp
:set binary noeol

vasek added a commit to vasek/jsdiff that referenced this issue Aug 30, 2018
vasek added a commit to vasek/jsdiff that referenced this issue Aug 30, 2018
vasek added a commit to vasek/jsdiff that referenced this issue Sep 3, 2018
kpdecker pushed a commit that referenced this issue Jan 5, 2019
@kpdecker
Copy link
Owner

kpdecker commented Jan 6, 2019

Released in 4.0.0

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

4 participants