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

Values containing hash (#) symbols are not included fully #8090

Open
1 task done
garyodonoghue opened this issue Nov 1, 2024 · 1 comment
Open
1 task done

Values containing hash (#) symbols are not included fully #8090

garyodonoghue opened this issue Nov 1, 2024 · 1 comment
Assignees
Labels

Comments

@garyodonoghue
Copy link

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

if i use a sample .netrc file as below:

machine blah.com
login test_user
password first#second

the # symbol in the password causes it to be not read entirely, it gets processed as just 'first', with the remaining characters "second" treated as a comment.

I believe this comes from this function

I understand comments need to be handled, but i think I would expect that if the password is all one 'word', i.e. no spaces, that it should still be treated as part of the password

Expected behavior

Values in .netrc containing hash symbols are processed as they are, including hash symbols, i.e. in the above example, the password value of "first#second" is used

Actual behavior

Value are truncated at the point of the location of the hash symbol due to the following characters being treated as comments, i.e. in the above example, the password value of "first" is used

Steps to reproduce

Have a .netrc file containing the following:

machine blah.com
login test_user
password first#second

Capture "Authorisation" header used in request from SPM to fetch binary target
Notice that it has the password truncated, so be "first", and does not include the entire value "first#second"

Sample unit test added to NetrcTests.swift to reproduce it :

func testHashSymbolInPassword() throws {
        let content = """
                    machine example.com
                    login anonymous
                    password qw#erty
                    """

        let netrc = try NetrcParser.parse(content)

        let machine = netrc.machines.first
        XCTAssertEqual(machine?.name, "example.com")
        XCTAssertEqual(machine?.login, "anonymous")
        XCTAssertEqual(machine?.password, "qw#erty")
    }

See output below:

Screenshot 2024-11-01 at 16 47 09

Swift Package Manager version/commit hash

main (0b569a1)

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0
Darwin mb-garyo 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000 arm64

@plemarquand plemarquand self-assigned this Nov 8, 2024
plemarquand added a commit to plemarquand/swift-package-manager that referenced this issue Nov 8, 2024
Hash symbols were always treated as the beginning of a comment even if
they were in the middle of a username or password. To address this
require some whitespace before a hash character before a comment is
parsed.

That patch also implements support for quoted fields so that passwords
can contain the sequence "foo #bar" without dropping "bar" as a comment.

Issue: swiftlang#8090
Issue
@plemarquand
Copy link
Contributor

Thanks for the detailed bug report!

I put up a patch that should handle qw#erty as a username or password. It also supports quoted values so that "qw #erty" is parsed completely.

plemarquand added a commit that referenced this issue Nov 14, 2024
Hash symbols were always treated as the beginning of a comment even if
they were in the middle of a username or password. To address this
require some whitespace before a hash character before a comment is
parsed.

That patch also implements support for quoted fields so that passwords
can contain the sequence "foo #bar" without dropping "bar" as a comment.

Issue: #8090
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants