Skip to content

Fix: URL-encode credentials in connectToNzbGet() to handle special characters - #10

Merged
dnzbk merged 1 commit into
nzbgetcom:masterfrom
MichielDean:fix/url-encode-credentials
Oct 12, 2026
Merged

dnzbk merged 1 commit into
nzbgetcom:masterfrom
MichielDean:fix/url-encode-credentials

Conversation

@MichielDean

Copy link
Copy Markdown

Description

  • Fixed connectToNzbGet() to URL-encode credentials before embedding them in the XML-RPC URL. Previously, special URL characters (@, #, %, $) in ControlPassword would corrupt the URL and crash the script with socket.gaierror: [Errno 11001] getaddrinfo failed.
  • The code already had a # TODO: encode username and password in URL-format comment noting this needed to be fixed.
  • This is the same bug fixed in Extension-Completion#25, Extension-FakeDetector#11, and Extension-PasswordDetector#6.

The problem

# TODO: encode username and password in URL-format
rpcUrl = 'http://%s:%s@%s:%s/xmlrpc' % (username, password, host, port)

Special characters in the password corrupt the URL structure:

  • @ separates credentials from host -> password spills into host/port position
  • # starts the URL fragment -> everything after # is discarded, text before # becomes the hostname
  • % is interpreted as a percent-encoding prefix

The fix

from urllib.parse import quote

rpcUrl = 'http://%s:%s@%s:%s/xmlrpc' % (quote(username, safe=""), quote(password, safe=""), host, port)

Testing

  • test_download_another_release_special_chars_password - integration test running the full script end-to-end with a password containing @, #, %, $
  • test_connectToNzbGet_encodes_special_chars - unit test verifying URL-breaking characters are percent-encoded in the XML-RPC URL
  • test_connectToNzbGet_normal_password - happy-path unit test verifying alphanumeric credentials produce a valid URL unchanged
  • Existing test_downlaod_another_release (with TestPassword) serves as the integration happy-path test

…aracters

Add: tests for URL-encoded credentials with special and normal characters
@dnzbk
dnzbk self-requested a review October 12, 2026 04:14

@dnzbk dnzbk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you

@dnzbk
dnzbk merged commit 59a0660 into nzbgetcom:master Oct 12, 2026
1 check passed
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.

2 participants