Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
ds300 merged 1 commit into ds300:master from NMinhNguyen:line-breaks
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/patch/__snapshots__/parse.test.ts.snap
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`the patch parser can handle files with CRLF line breaks 1`] = `
Array [
Object {
"lines": Array [
"this is a new file
",
],
"mode": 420,
"noNewlineAtEndOfFile": false,
"path": "banana.ts",
"type": "file creation",
},
]
`;

exports[`the patch parser works for a simple case 1`] = `
Array [
Object {
Expand Down
12 changes: 12 additions & 0 deletions src/patch/parse.test.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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`, () => {
Copy link
Contributor Author

@NMinhNguyen NMinhNguyen Oct 20, 2018

Choose a reason for hiding this comment

The 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

josgraha reacted with thumbs up emoji
expect(parsePatch(crlfLineBreaks)).toMatchSnapshot()
})
})
2 changes: 1 addition & 1 deletion src/patch/parse.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class PatchParser {
}

private parseFileModification() {
const startPath = this.currentLine.slice("--- ".length)
const startPath = this.currentLine.trim().slice("--- ".length)
Copy link
Contributor Author

@NMinhNguyen NMinhNguyen Oct 24, 2018
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's any implications from using .trim() as opposed to trimming from the end e.g.

const trimEnd = str => str.replace(/\s+$/, '')

this.nextLine()
const endPath = this.currentLine.trim().slice("--- ".length)
this.nextLine()
Expand Down

AltStyle によって変換されたページ (->オリジナル) /