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

parsePatch combines patches from multiple files into a single IUniDiff when there is no "Index" line #135

Closed
ramya-rao-a opened this issue Sep 15, 2016 · 3 comments

Comments

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Sep 15, 2016

parsePatch() in case of multiple files works well if the diff data for each file is preceeded by the "Index" line. In the absence of this "Index" line all patches are collapsed against the first file.

Since the "Index" line is optional, I would expect the below to work

Example: Pass the below diff string to parsePatch(). It is expected to return an array of 3 IUniDiff objects (each with 1 patch) for the 3 files. Instead it returns 1 IUniDiff object with 3 patches

--- C:\GoCode\src\github.com\golang\example\hello\hello.go 2016-09-14 14:38:47.780660100 -0700\r\n+++ C:\GoCode\src\github.com\golang\example\hello\hello.go.17760.renamed 2016-09-14 14:41:25.830187200 -0700\r\n@@ -14,6 +14,6 @@\r\n printMe123 := "!selpmaxe oG ,olleH"\r\n \r\n //sdsd\r\n- fmt.Println(stringutil.Reverse12(printMe123))\r\n+ fmt.Println(stringutil.Reverse1234(printMe123))\r\n \r\n }\r\n--- C:\GoCode\src\github.com\golang\example\stringutil\reverse.go 2016-09-13 20:14:42.643587100 -0700\r\n+++ C:\GoCode\src\github.com\golang\example\stringutil\reverse.go.17760.renamed 2016-09-14 14:41:25.865210500 -0700\r\n@@ -18,7 +18,7 @@\r\n package stringutil\r\n \r\n // Reverse returns its argument string reversed rune-wise left to right.\r\n-func Reverse12(s string) string {\r\n+func Reverse1234(s string) string {\r\n r := []rune(s)\r\n for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {\r\n r[i], r[j] = r[j], r[i]\r\n--- C:\GoCode\src\github.com\golang\example\stringutil\reverse_test.go 2016-09-13 20:14:43.883948400 -0700\r\n+++ C:\GoCode\src\github.com\golang\example\stringutil\reverse_test.go.17760.renamed 2016-09-14 14:41:25.895199900 -0700\r\n@@ -26,7 +26,7 @@\r\n {"Hello, 世界", "界世 ,olleH"},\r\n {"", ""},\r\n } {\r\n- got := Reverse12(c.in)\r\n+ got := Reverse1234(c.in)\r\n if got != c.want {\r\n t.Errorf("Reverse(%q) == %q, want %q", c.in, got, c.want)\r\n }\r\n"

@ramya-rao-a
Copy link
Contributor Author

ramya-rao-a commented Sep 15, 2016

the issue is here https://github.com/kpdecker/jsdiff/blob/master/src/patch/parse.js#L86

if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\')

The above should exclude cases when the diffstr starts with +++ and ---

@ramya-rao-a ramya-rao-a changed the title parsePatch combines patches from multiple files into a single IUniDiff parsePatch combines patches from multiple files into a single IUniDiff when there is no "Index" line Sep 15, 2016
kpdecker added a commit that referenced this issue Oct 1, 2016
Parse multiple files in the absence of the Index line to fix #135 issue.
@kpdecker
Copy link
Owner

kpdecker commented Oct 9, 2016

Released in 3.0.1

@ramya-rao-a
Copy link
Contributor Author

Thanks!

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

2 participants