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

Handle CRLF line breaks in the patch parser #91

ds300 merged 1 commit into ds300:master from NMinhNguyen:line-breaks
Oct 24, 2018

Conversation

Copy link
Contributor

@NMinhNguyen NMinhNguyen commented Oct 20, 2018
edited
Loading

I noticed that if a patch file was checked out on Windows and it contained CRLF linebreaks, then patch-package would fail on file creation because this condition would be false due to startPath containing a trailing \r (carriage return) character: https://github.com/ds300/patch-package/blob/54a168b/src/patch/parse.ts#L297

After some investigation, it turned out that this was happening because https://github.com/ds300/patch-package/blob/54a168b/src/patch/parse.ts#L387 was splitting patch file contents on \n and so every line contained a trailing \r

(削除) Interestingly, I couldn't get yarn test --runInBand to pass locally even on a fresh checkout (without my changes) 🙁 (削除ここまで) Thanks to CI, I've now managed to ensure all tests pass.

@NMinhNguyen NMinhNguyen changed the title (削除) Handle line breaks such as CRLF in the patch parser (削除ここまで) (追記) Handle CRLF line breaks in the patch parser (追記ここまで) Oct 20, 2018
This fixes an issue where file creation wasn't occurring
on Windows due to `startPath !== "/dev/null"`
because `startPath` had a trailing `\r`.
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

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+$/, '')

Copy link
Owner

ds300 commented Oct 24, 2018

This looks great, thanks! Sorry it took me a while to get around to it.

NMinhNguyen reacted with thumbs up emoji

@ds300 ds300 merged commit aea8f4d into ds300:master Oct 24, 2018
Copy link
Owner

ds300 commented Oct 24, 2018

published in patch-package@6.0.0-11 Thanks again! 🎉

NMinhNguyen and josgraha reacted with hooray emoji

Copy link
Contributor Author

No problem, thank you for reviewing and releasing! 🙂

@NMinhNguyen NMinhNguyen deleted the line-breaks branch October 25, 2018 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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