Skip to content

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

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

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

Conversation

@bobo-xxx
Copy link
Copy Markdown

Fixes #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
Contributor

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

Fixes parsing of .pg_service.conf values containing # by altering how the service-file parser handles comments, so passwords like abc#123 aren’t truncated during connect_service().

Changes:

  • Update parse_service_info() to construct ConfigObj with comment_tokens=[] to disable comment parsing.

💡 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.

There’s test coverage for service-file parsing (test_pg_service_file), but it doesn’t cover the regression fixed here (passwords containing #). Please extend/add a test case with password=abc#123 (and ideally one with a trailing comment after the value) to ensure the password is preserved and comment handling remains correct.

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.

Setting comment_tokens=[] disables all #/; comment parsing for the entire .pg_service.conf. That will likely break valid service files that contain full-line comments after the first section header (those # ... lines would no longer be treated as comments and can trigger a parse error). Consider using a parser/configuration that keeps full-line comments but disables inline comment parsing (e.g., a ConfigParser setup with inline_comment_prefixes=() while retaining comment_prefixes, or another ConfigObj option that only disables inline comments).

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