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 .netrc parsing #7698

Merged
merged 3 commits into from
Jan 3, 2025
Merged

Fix .netrc parsing #7698

merged 3 commits into from
Jan 3, 2025

Conversation

fredrik-eriksson
Copy link
Contributor

Fixes: #7177

It seems that the current Tokenizer-implementation splits the netrc tokens on a (string) separator of " \n\t" instead of splitting on any of the whitespace characters which leads to the issue described in #7177.

This implementation splits the content of netrc on any whitespace character using a regex instead, but should otherwise use the same strategy for parsing. I'm not very familiar with C++ (or QT) and does not completely understand the code, so although this solution seems to work for me, I would appreciate a review 🙂

Thanks!

@mgallien mgallien added this to the 3.15.3 milestone Jan 2, 2025
@mgallien mgallien self-requested a review January 2, 2025 10:59
Copy link
Collaborator

@mgallien mgallien left a comment

Choose a reason for hiding this comment

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

thanks for the PR
there would still be failing tests
see

FAIL! : TestNetrcParser::testValidNetrc() Compared values are not the same
Actual (parser.find("frob")) : std::pair(""user", "'space")
Expected (qMakePair(QString("user with spaces"), QString("space pwd"))): std::pair("user with spaces", "space pwd")
Loc: [/home/mgallien/work/nextcloud/desktop/test/testnetrcparser.cpp(60)]

I also needed to remove the QEXPECT_FAIL instances from test/testnetrcparser.cpp file
can you add those changes to the PR ?

@fredrik-eriksson
Copy link
Contributor Author

I think this is as good as I can do. The only test that still fail is username and passwords containing whitespaces, and I think that would require a bigger refactoring. I've commented out that test for now to enable the rest of them.

Copy link
Collaborator

@mgallien mgallien left a comment

Choose a reason for hiding this comment

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

thanks @fredrik-eriksson
can you fix the missing signed off comment and fix my inline comment ?
apart from that, I fully agree that your change can be merged as is and is already a big improvement

test/testnetrcparser.cpp Outdated Show resolved Hide resolved
@fredrik-eriksson
Copy link
Contributor Author

Thanks for the feedback, I hope I got it right this time 🙂

Fixes: nextcloud#7177
Signed-off-by: Fredrik Eriksson <[email protected]>
Also fixes handling of empty netrc.

Signed-off-by: Fredrik Eriksson <[email protected]>
Test for spaces in usernames and passwords is disabled for now as it's
not supported by current implementation.

Signed-off-by: Fredrik Eriksson <[email protected]>
@mgallien
Copy link
Collaborator

mgallien commented Jan 3, 2025

@fredrik-eriksson thanks for the very fast review cycles
my plan is to get this merged now and backported to the current stable branch for a release next week
congratulations for your contribution and many thanks for the fix

@mgallien mgallien merged commit 1e91c0e into nextcloud:master Jan 3, 2025
10 of 14 checks passed
@mgallien
Copy link
Collaborator

mgallien commented Jan 3, 2025

/backport to stable-3.15

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.

[Bug]: nextcloud client failed to parse netrc
2 participants