fix: preserve hash character in pg_service.conf passwords#1578
fix: preserve hash character in pg_service.conf passwords#1578bobo-xxx wants to merge 1 commit intodbcli:mainfrom
Conversation
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
There was a problem hiding this comment.
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 constructConfigObjwithcomment_tokens=[]to disable comment parsing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| skipped_lines = skip_initial_comment(f) | ||
| try: | ||
| service_file_config = ConfigObj(f) | ||
| service_file_config = ConfigObj(f, comment_tokens=[]) |
There was a problem hiding this comment.
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.
| skipped_lines = skip_initial_comment(f) | ||
| try: | ||
| service_file_config = ConfigObj(f) | ||
| service_file_config = ConfigObj(f, comment_tokens=[]) |
There was a problem hiding this comment.
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).
Fixes #1575
The
#character is treated as a comment delimiter by ConfigObj, which truncates passwords likeabc#123toabc.This fix adds
comment_tokens=[]to theConfigObj()call inparse_service_info()to disable comment parsing, allowing#characters within password values.Before
After