-
-
Notifications
You must be signed in to change notification settings - Fork 313
Handle CRLF line breaks in the patch parser #91
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,15 @@ index 2de83dd..842652c 100644 | |
file | ||
` | ||
|
||
const crlfLineBreaks = `diff --git a/banana.ts b/banana.ts | ||
new file mode 100644 | ||
index 0000000..3e1267f | ||
--- /dev/null | ||
+++ b/banana.ts | ||
@@ -0,0 +1 @@ | ||
+this is a new file | ||
`.replace(/\n/g, "\r\n") | ||
|
||
describe("the patch parser", () => { | ||
it("works for a simple case", () => { | ||
expect(parsePatch(patch)).toMatchSnapshot() | ||
|
@@ -105,4 +114,7 @@ describe("the patch parser", () => { | |
it("is OK when blank lines are accidentally created", () => { | ||
expect(parsePatch(accidentalBlankLine)).toEqual(parsePatch(patch)) | ||
}) | ||
it(`can handle files with CRLF line breaks`, () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strictly speaking, I could've written a more focused test that does expect(parsePatch(crlfLineBreaks)[0].type).toBe("file creation") Let me know if you'd prefer that instead of a snapshot test |
||
expect(parsePatch(crlfLineBreaks)).toMatchSnapshot() | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,7 +266,7 @@ class PatchParser { | |
} | ||
|
||
private parseFileModification() { | ||
const startPath = this.currentLine.slice("--- ".length) | ||
const startPath = this.currentLine.trim().slice("--- ".length) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if there's any implications from using const trimEnd = str => str.replace(/\s+$/, '') |
||
this.nextLine() | ||
const endPath = this.currentLine.trim().slice("--- ".length) | ||
this.nextLine() | ||
|