Skip to content

Have a problem with "createTwoFilesPatch" method #254

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

Closed
lwf804 opened this issue May 3, 2019 · 3 comments
Closed

Have a problem with "createTwoFilesPatch" method #254

lwf804 opened this issue May 3, 2019 · 3 comments
Labels

Comments

@lwf804
Copy link

lwf804 commented May 3, 2019

I use jsdiff with diff2html to show diff of two strings.
Here: https://codepen.io/lwf804/pen/KYOxBL?editors=1001
image

I don't know why line one is changed. Can you explain for me?
Thanks!

@antonin-lebrard
Copy link

Its because there is a newline character at the end of the stringTwo:

var stringOne = "string 1",
      stringTwo = `string 1 // <= here there is a \n character that the stringOne doesn't have

b`

@ExplodingCabbage
Copy link
Collaborator

Correct. This matches the behaviour of the diff Unix util.

@ExplodingCabbage
Copy link
Collaborator

(You can preprocess your strings to ensure they always end with a trailing newline if you don't like this behaviour.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants