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

Fix parsing of mode lines with trailing space #38

Merged
merged 1 commit into from
Dec 26, 2022
Merged

Conversation

bluekeyes
Copy link
Owner

If a patch is passed through a system that converts line endings to '\r\n', mode lines end up with trailing whitespace that confuses strconv.ParseInt. In Git, this is avoided by using strtoul() for parsing, which stops at the first non-digit character.

Changing line endings in patch content itself can cause other problems so it is best to avoid this transform, but if it does happen, it shouldn't cause a parse error.

Fixes #37. I might want to revisit this in the future in favor of something more like strtoul(), but for now, I think it is still better to fail on obviously wrong numbers than to silently parse some part of them.

If a patch is passed through a system that converts line endings to
'\r\n', mode lines end up with trailling whitespace that confuses
ParseInt. In Git, this is avoided by using strtoul() for parsing, which
stops at the first non-digit character.

Changing line endings in patch content itself will cause other problems
so it is best to avoid this transform, but if it does happen, it
shouldn't cause a parse error.
@bluekeyes bluekeyes merged commit 981bc4b into master Dec 26, 2022
@bluekeyes bluekeyes deleted the fix-mode-parsing branch December 26, 2022 22:56
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

Successfully merging this pull request may close these issues.

gitdiff: line 63: git file header: invalid mode line: invalid syntax
1 participant