Skip to content

fix: decode escaped unix domain socket output URI paths - #101

Open
reginaldalfret wants to merge 1 commit into
Netflix:mainfrom
reginaldalfret:fix/unix-socket-escaped-path
Open

reginaldalfret wants to merge 1 commit into
Netflix:mainfrom
reginaldalfret:fix/unix-socket-escaped-path

Conversation

@reginaldalfret

Copy link
Copy Markdown

Summary

Decode the path component of a unix:// output URI before connecting or sending to it. For example, a configured unix domain socket path containing escaped spaces (%20) or other percent-encoded characters currently attempts to reach a socket file with the literal escape sequence rather than connecting to the intended path containing spaces.

This mirrors the decoding behavior implemented for file:// output URIs in #97.

Root cause

SocketWriter._init_unix was directly assigning urlparse(location).path to self._address without calling unquote(). When a URI such as unix:///run/spectatord/my%20service/spectatord.unix is provided, urlparse().path preserves the percent-encoded sequences, causing socket communication to target the wrong filesystem path. Additionally, self._family was referencing socket.AF_UNIX directly at initialization rather than using getattr(socket, "AF_UNIX", ...), causing AttributeError on environments lacking AF_UNIX.

Changes

  1. spectator/writer/socket_writer.py:
    • Applied unquote(urlparse(location).path) in _init_unix.
    • Safely resolved self._family via getattr(socket, "AF_UNIX", socket.AF_INET) and added a defensive guard in _acquire_socket if AF_UNIX is unsupported on the host platform.
  2. tests/writer/test_socket_writer_unix.py:
    • Added test_socket_writer_unix_escaped_address verifying that escaped URI paths like %20 are correctly decoded.
    • Added test_socket_writer_unix_escaped_path verifying end-to-end datagram delivery over a path containing spaces.
    • Added @unittest.skipUnless(hasattr(socket, "AF_UNIX"), ...) to prevent socket server test crashes on platforms lacking AF_UNIX.

Verification

  • pytest tests/writer/test_socket_writer_unix.py passed cleanly.
  • mypy --platform linux spectator tests passed across all 59 source files with 0 errors.
  • pylint --rcfile=.pylintrc-relaxed rated both changed files 10.00/10.

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
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.

1 participant