Repository navigation
Conversation
git-credential store treats only LF as an EOL character, but reads the CR in a CR terminated line as part of the entry. Since the entries are URLs, CR can never be a valid character in an entry. [1] While we don't encourage users to manually edit the credential file, the format is simple enough and documented well enough that users do sometimes do that. Most editors on Windows produce CRLF as EOL characters. Users currently need to be careful when manually editing the credential file on Windows to not add stray CR characters into the file. We have tests around when we consider entries with CRLF valid and not valid, but they only seem to test the known quirks of the existing implementation, not some expectations founded in some systemic design decisions. Since the entries can never validly contain a CR character we should just treat CRLF as an EOL character. Start treating it that way and adjust the old tests. [1] https://www.rfc-editor.org/info/rfc1738/#section-2.2 Signed-off-by: Matthias Aßhauer <mha1993@live.de>
| invalid_credential_test "username/password" https://pass@example.com | ||
|
|
||
| test_expect_success 'get: credentials with DOS line endings are invalid' ' | ||
| test_expect_success 'get: credentials with DOS line endings are valid' ' |
There was a problem hiding this comment.
Hmm. This reverts c03859a, and I wonder whether we're not actually making things worse that way: We're essentially walking back a promise that we've upheld for 6 years...
There was a problem hiding this comment.
From my perspective as a user, it seems both normal and reasonable for "Git for Windows" to support a credentials file with CRLF line endings, since the program is natively intended for Windows.
Also, CRLF handling seems currently to be inconsistent: CRLF credentials are considered invalid at line 146 (test_expect_success 'get: credentials with DOS line endings are invalid'), but valid at line 163 (test_expect_success 'get: credentials with path and DOS line endings are valid') ?!
There was a problem hiding this comment.
@i80487 what you missed, though, is that we're not even talking about user-facing files, but about files that are written by Git. Some users may feel free to muck with those, and change the line endings. That's what this PR tries to accommodate. I don't think it would set a good precedent, though. Soon we'd have to add patches left and right to accommodate for all sorts of subtle inconsistencies users would introduce into Git's internal files, when it would be better to draw a hard line: Iff you want to mess with those files, you're completely on your own, we won't cover up your mistakes.
There was a problem hiding this comment.
@dscho: As a software engineer, I fully understand that you may not want to support every possible case that users might introduce.
As an end user of "git-for-windows", please note that .gitconfig and .git-credentials are text files stored in the home directory. They’re not internal Git files stored in a .git folder, but configuration and credential files. As with many other applications, it seems to me both legitimate and reasonable to be able to edit them (while following the syntax) with a text editor rather than having to use Git commands.
There was a problem hiding this comment.
@i80487 I understand your desire, but you're mixing two concepts here. .gitconfig is supposed to be edited by the user, typically using the git config command. The .git-credentials file is in a very different category, it is the backing file of git-credential--store, and as such it totally is not meant to be edited by users, certainly not directly via a text editor. Just because you can does not mean that it is a good idea.
Take for example packfiles. You can edit .pack files with a hex editor, it's just really a terrible idea. You might corrupt it in ways that Git does not expect. The end result is that it no longer works as you want, and the only reason for that is that you edited the file manually, and you messed up.
It's the same, really, when you edit the .git-credentials file. You have to abide by the format Git expects. And if you save with CR/LF line endings, well, there you go, you messed up, the file is no longer in a format Git handles because it did not expect you to mess it up. It expected that file to be under its own control. And you broke that contract.
I don't think that it is a good idea to change Git in a way that it tries to work around such mess-ups. That would just set this awful precedent where I have to spend even more time on addressing problems that aren't caused by bugs in Git, but purely by users doing something that they shouldn't have done in the first place, because it's outside of what is supported.
There was a problem hiding this comment.
@dscho : I understand and respect your point of view. I appreciate you taking the time to review my request and discuss it with me. Feel free to close this pull request and close the issue as well.
|
@rimrul I haven't heard of any convincing argument why an internal file of Git should be made user-editable, and as such I am inclined to close this PR without merging it. Do you agree? |
git-credential store treats only LF as an EOL character, but reads the CR in a CR terminated line as part of the entry. Since the entries are URLs, CR can never be a valid character in an entry.
While we don't encourage users to manually edit the credential file, the format is simple enough and documented well enough that users do sometimes do that. Most editors on Windows produce CRLF as EOL characters. Users currently need to be careful when manually editing the credential file on Windows to not add stray CR characters into the file.
We have tests around when we consider entries with CRLF valid and not valid, but they only seem to test the known quirks of the existing implementation, not some expectations founded in some systemic design decisions.
Since the entries can never validly contain a CR character we should just treat CRLF as an EOL character. Start treating it that way and adjust the old tests.