Skip to content

fix: preserve hash character in pg_service.conf passwords#3

Open
bobo-xxx wants to merge 1 commit into
mainfrom
clawoss/fix/pg-service-conf-hash
Open

fix: preserve hash character in pg_service.conf passwords#3
bobo-xxx wants to merge 1 commit into
mainfrom
clawoss/fix/pg-service-conf-hash

Conversation

@bobo-xxx
Copy link
Copy Markdown
Owner

Fixes dbcli#1575

The # character is treated as a comment delimiter by ConfigObj, which truncates passwords like abc#123 to abc.

This fix adds comment_tokens=[] to the ConfigObj() call in parse_service_info() to disable comment parsing, allowing # characters within password values.

Before

service_file_config = ConfigObj(f)

After

service_file_config = ConfigObj(f, comment_tokens=[])

The # character was being treated as a comment delimiter by ConfigObj,
truncating passwords like abc#123 to abc. Added comment_tokens=[] to
disable this behavior.

Fixes dbcli#1575
Copilot AI review requested due to automatic review settings April 18, 2026 08:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts parsing of ~/.pg_service.conf so passwords containing # are not truncated during service lookup (Fixes dbcli#1575).

Changes:

  • Updates parse_service_info() to construct ConfigObj with comment_tokens=[] to prevent # from being treated as a comment delimiter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pgcli/main.py
skipped_lines = skip_initial_comment(f)
try:
service_file_config = ConfigObj(f)
service_file_config = ConfigObj(f, comment_tokens=[])
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

Setting comment_tokens=[] disables all comment parsing, so standard pg_service.conf files containing comment lines beginning with '#' (not just at the top) will be treated as invalid entries and may raise ParseError. This is a functional regression versus the previous behavior where '#' comment lines were accepted; consider keeping full-line comment handling while only disabling inline comment stripping (e.g., switch to configparser with inline_comment_prefixes disabled, or configure ConfigObj to not strip inline comments but still ignore full-line comments).

Copilot uses AI. Check for mistakes.
Comment thread pgcli/main.py
skipped_lines = skip_initial_comment(f)
try:
service_file_config = ConfigObj(f)
service_file_config = ConfigObj(f, comment_tokens=[])
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

This change alters parsing semantics for pg_service.conf; please add/adjust tests to cover passwords containing '#' and also ensure that comment lines (e.g., lines starting with '#') within/between sections still parse correctly after the change.

Copilot uses AI. Check for mistakes.
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